• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Doesn't work?

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
Ok, so i finnaly made a knockback(a simple one) and the map just won't start.
Can someone tell me what's wrong with it?

JASS:
scope vars initializer Init
globals
     constant integer id = 'spel'
     private unit target
     private real distance = 0
     private unit caster
     private location l
     private real angle
endglobals
private function actions takes nothing returns nothing
    set target = GetSpellTargetUnit()
    set caster = GetSpellAbilityUnit()
    set c = GetUnitLoc(caster)
    set angle = GetUnitFacing(caster)
endfunction
private private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t, function actions)
endfunction

private function Trig_Spell_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == id
endfunction

private function Move takes nothing returns nothing
    call SetUnitPositionLoc(target, PolarProjectionBJ(l, distance, angle)
    set distance = distance + 6
endfunction

private function Trig_Spell_Actions takes nothing returns nothing
    local integer count = 100
    local timer t
    loop
    exitwhen count == 0
    call TimerStart(t,0.04,false,function Move)
    set count = count - 1
    endloop
    call DestroyTimer(t)
endfunction

//===========================================================================
private function InitTrig_Spell takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    local integer i = 0
    loop
    exitwhen i == 16
    call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
    set i = i + 1
endloop
    call TriggerAddCondition(t, Condition(function Trig_Spell_Conditions) )
    call TriggerAddAction( t, function Trig_Spell_Actions )
endfunction
endscope

Thx!
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
"private" declared twice here:

private private function Init takes nothing returns nothing


You have a sintax error here:

call SetUnitPositionLoc(target, PolarProjectionBJ(l, distance, angle)


You forgot to close the brackets.

You seem to be firing a uninitialized timer here:

JASS:
private function Trig_Spell_Actions takes nothing returns nothing
    local integer count = 100
    local timer t
    loop
    exitwhen count == 0
    call TimerStart(t,0.04,false,function Move)
    set count = count - 1
    endloop
    call DestroyTimer(t)
endfunction

You're missing the good 'ol set t = CreateTimer() probably at the beginning of the loop.

And another thing, having two initializing functions:

JASS:
private private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t, function actions)
endfunction

JASS:
private function InitTrig_Spell takes nothing returns nothing
    local trigger t = CreateTrigger( )
    local integer i = 0
    loop
    exitwhen i == 16
    call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
    set i = i + 1
endloop
    call TriggerAddCondition(t, Condition(function Trig_Spell_Conditions) )
    call TriggerAddAction( t, function Trig_Spell_Actions )
endfunction

is really weird. I'm guessing you didn't want that, because you can put everything you need in a single function.

This part seems wrong too:

JASS:
private function actions takes nothing returns nothing
    set target = GetSpellTargetUnit()
    set caster = GetSpellAbilityUnit()
    set c = GetUnitLoc(caster)
    set angle = GetUnitFacing(caster)
endfunction
private private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t, function actions)
endfunction

as it will fire for any spell that is casted.

One last thing that's not really a problem, but is weird. One time you seem to use TriggerRegisterAnyUnitEventBJ and the next time you replace it with natives. My guess would be that you modified someone else's code?

Anyways, judging from this code, I would say that you don't quite understand it.
 
Level 8
Joined
Jul 28, 2008
Messages
211
It is my code, but I wanted to make a different spell and I changed my mind, so I left some unneeded things here.
About those natives, someone told me that it was better than the BJ so i used it one time, and when i was making the other i was too lazy to put it in.

I corected some things, but it still reports an error when i try to save the map.

JASS:
scope vars initializer InitTrig_Spell
globals
     constant integer id = 'spel'
     private unit target
     private real distance = 0
     private unit caster
     private location l
     private real angle
endglobals


private function Trig_Spell_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == id
endfunction


private function Move takes nothing returns nothing
    call SetUnitPositionLoc(target, PolarProjectionBJ(l, distance, angle) )
    set distance = distance + 6

private function Trig_Spell_Actions takes nothing returns nothing
    set target = GetSpellTargetUnit()
    set caster = GetSpellAbilityUnit()
    set l = GetUnitLoc(caster)
    set angle = GetUnitFacing(caster)
    local integer count = 100
    local timer ti = CreateTimer()
    loop
    exitwhen count == 0
    set count = count - 1
    call TimerStart(ti, 0.04, true, function Move)
    endloop
    call DestroyTimer(ti)
endfunction

//===========================================================================
private function InitTrig_Spell takes nothing returns nothing
    local trigger tr = CreateTrigger(  )
    local integer i = 0
    loop
    exitwhen i == 16
    call TriggerRegisterPlayerUnitEvent(tr,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
    set i = i + 1
endloop
    call TriggerAddCondition(tr, Condition(function Trig_Spell_Conditions) )
    call TriggerAddAction( tr, function Trig_Spell_Actions )
endfunction
endscope

It says that the error is in Trig_Spell_Actions.
 
Level 4
Joined
Mar 14, 2009
Messages
98
You missed "endfunction" for Move.

You declared locals after doing stuff (setting variables) in Trig_Spell_Actions.
I don't know why you're starting the timer 100 times. Why not just start it once?

Also, it won't work because you're destroying the timer right after you've started it. You have to destroy it once it has finished its job.

Oh, and you have to have some way to stop the timer once it has done enough iterations (or else the target will keep getting knocked back for the rest of eternity).
 
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
Oh, and you have to have some way to stop the timer once it has done enough iterations.

Yeah, some kind of an attachment system. But I'm guessing it's a bit advanced for you atm. Practice typing your code to get the habit of closing functions, loops etc. Also, try to read a few tutorials to understand what you can and can't do in JASS.
 
Level 4
Joined
Mar 14, 2009
Messages
98
Well, from the looks of everything else, this doesn't seem to be going for MUI anyway. A simple counter that increments every iteration and a condition that destroys the timer should be enough.

Oh, and why not use TriggerRegisterAnyUnitEventBJ? It looks so much cleaner and you'll lose at most a few microseconds.
 
Status
Not open for further replies.
Top