HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

What's wrong?

01-12-2008, 06:36 PM#1
Gwypaas
Collapse JASS:
scope Circle
globals
    private constant integer DISTFROMCAST = 500 // The distance from the caster
    private constant integer ABILID = 'A001'
endglobals
private struct dat
     unit array units[50]
     timer t
     unit castu
     player castp
     integer angle =0
     real x1
     real y1
     real x2
     real y2
endstruct
private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ABILID
endfunction

private function Actions takes nothing returns nothing
    local dat d = dat.create()
    local integer i = 0
    set d.castu = GetSpellAbilityUnit()
    set d.castp = GetOwningPlayer(d.castu)
    set d.x1 = GetUnitX(d.castu)
    set d.y1 = GetUnitY(d.castu)
    loop
        exitwhen i==360
        set d.x2 = d.x1+DISTFROMCAST*Cos(i*bj_DEGTORAD)
        set d.y2 = d.y1+DISTFROMCAST*Sin(i*bj_DEGTORAD)
        call AddSpecialEffectLoc("Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl", Location(d.x2, d.y2))
        set i = i+1
    endloop
    call dat.destroy(d)
endfunction

//===========================================================================
public function InitTrig_Make_Circle takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction
endscope

I tested with debug messages but the trigger seemed to not run at all.
01-12-2008, 08:45 PM#2
Vexorian
Quote:
public function InitTrig_Make_Circle takes nothing returns nothing
01-12-2008, 08:59 PM#3
Gwypaas
What should I change it to? When I save the map it saves perfectly but it doesn't go off when I use it.
01-12-2008, 09:12 PM#4
Zandose
Quote:
Originally Posted by Gwypaas
What should I change it to? When I save the map it saves perfectly but it doesn't go off when I use it.
I think he meant that you needed to change "InitTrig_Make_Circle" to just "InitTrig". Also, make sure that you name the trigger (the left window) the same as the scope name.
01-12-2008, 09:13 PM#5
xombie
No, its that if you have public function InitTrig then it will not be called InitTrig, it will be ScopeName_InitTrig. Get rid of the public.
01-12-2008, 09:20 PM#6
Vexorian
Zandose is right, xombie is wrong.

I am gonna add initializers to scopes and end this ridiculous WE dependency.
01-12-2008, 09:27 PM#7
xombie
Quote:
Originally Posted by Vexorian
I am gonna add initializers to scopes and end this ridiculous WE dependency.

Thank you.

I figured I was wrong about 30 seconds after I made the post, but why just InitTrig? Wouldn't that make the function name Circle_InitTrig and thus not be called at game initialization?
01-12-2008, 09:33 PM#8
Zandose
Hope I get this right. When the script/triggers are compiled InitTrig it changed to InitTrig_ScopeName. Also when the scripts compiled the editor has some internal thing which uses the triggers name (left window) and just InitTrig to make "call InitTrig_TriggerName()", which is called when the game starts and thus starts your code/InitTrig function. That's why the trigger name matchs the scope name so compiler changes your InitTrig to InitTrig_ScopeName and the editor makes "call InitTrig_TriggerName" which both match each other and thus your function is called.

Adding a public to a function adds "_ScopeName" to the end of the functions name.
Adding a private to a function adds "ScopeName(a random number)__" to the begining of the functions name.
01-12-2008, 09:39 PM#9
HINDYhat
When the function's name is InitTrig, and the function is public, the scope's name gets placed after the function name. So something like:
Collapse JASS:
scope lawl
    public function InitTrig takes nothing returns nothing
    endfunction
endscope
Will compile to:
Collapse JASS:
function InitTrig_lawl takes nothing returns nothing
endfunction
On the other hand, any other (correct me if I'm wrong) function name will be compiled to <scopename>_<functionname>

And that's also why it's important that your 'trigger' name be the same as the scope's name.
01-12-2008, 09:48 PM#10
Zandose
@HINDYhat
Your correct. I saw my mistake and was trying to fix it but you posted before I could.
01-12-2008, 09:49 PM#11
Gwypaas
if I change the name it InitTrig it still doesn't go off. So it's not that, I tried remove the public too. Didn't change anything.
01-12-2008, 09:50 PM#12
xombie
Oh, I did not know that. I've been just using libraries for their initializer utility, haven't had much experience with the way InitTrig works. Sorry guys.
01-12-2008, 09:57 PM#13
Zandose
Are you sure you changed the trigger name? Look at the attached picture below to see what I mean.
Attached Images
File type: jpgWE.jpg (35.9 KB)
01-12-2008, 09:59 PM#14
Vexorian
Your trigger and the scope must have exactly the same name, and I recommend not using spaces at all in the trigger's name.
01-13-2008, 10:44 AM#15
Gwypaas
Ok now the trigger looks like this:
Collapse JASS:
scope Circle
globals
    private constant integer DISTFROMCAST = 500 // The distance from the caster
    private constant integer ABILID = 'A001'
endglobals
private struct dat
     unit array units[50]
     timer t
     unit castu
     player castp
     integer angle =0
     real x1
     real y1
     real x2
     real y2
endstruct
private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ABILID
endfunction

private function Actions takes nothing returns nothing
    local dat d = dat.create()
    local integer i = 0
    set d.castu = GetSpellAbilityUnit()
    set d.castp = GetOwningPlayer(d.castu)
    set d.x1 = GetUnitX(d.castu)
    set d.y1 = GetUnitY(d.castu)
    loop
        exitwhen i==360
        set d.x2 = (d.x1+DISTFROMCAST)*Cos(i*bj_DEGTORAD)
        set d.y2 = (d.y1+DISTFROMCAST)*Sin(i*bj_DEGTORAD)
        call AddSpecialEffectLoc("Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl", Location(d.x2, d.y2))
        set i = i+1
    endloop
    call dat.destroy(d)
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction
endscope

But the problem I have now is that the trigger doesn't create a circle around the hero instead it creates a circle with different size, and the size depends on how far the hero is away from the middle.