• 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 loop doesn't work

Status
Not open for further replies.
Level 11
Joined
Sep 14, 2009
Messages
284
Hey. I just started to learn jass and it's fine so far but I don't understand why this loop doesn't work, none of the actions/functions/we in the loop is executed but the actions before the loop is.

Some lines are just for debug and I know I miss some nullifies but that's not what i need help with.

JASS:
//===========================================================================
function IceFCastCond takes nothing returns boolean
return GetSpellAbilityId()=='A004'
endfunction

function IceFCastAct takes nothing returns nothing
local unit IceFCastCaster
local unit IceFCastTarDum
local location IceFCastPointA
local location IceFCastPointB
local boolean IceFCastActive
local integer IceFCastLoop

set IceFCastCaster = GetTriggerUnit()
set IceFCastPointA = GetSpellTargetLoc()
set IceFCastActive = true
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Hey")
loop
    exitwhen IceFCastLoop > 5
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Loop")
    set IceFCastPointB = PolarProjectionBJ(IceFCastPointA, 20.00, (72.00 * I2R(GetForLoopIndexA())))
    set IceFCastTarDum = CreateUnitAtLoc(GetOwningPlayer(IceFCastCaster), 'u002', IceFCastPointB, 0.00)
    set IceFCastB = null
    set IceFCastLoop = IceFCastLoop + 1
endloop
endfunction

//===========================================================================
function InitTrig_IceFlower takes nothing returns nothing
local trigger IceFCast
set IceFCast=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(IceFCast, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(IceFCast, Condition(function IceFCastCond))
call TriggerAddAction(IceFCast, function IceFCastAct)
endfunction
 
Level 11
Joined
Sep 14, 2009
Messages
284
Ok thanks it was becuase it lacked an initial value.

I prefer the integers.You are using the IceFCastLoop integer as the integer of the loop,but you are using A Index

You mean instead of using GetForLoopIndexA I shall use IceFCastLoop? Both works but maybe the other is better I dont know.

Also another question is setting variables to null the same thing as a leak removal in gui?
Like "set pointvariable = null" is actually the function of "call RemoveLocation"?
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
In vJASS we now have for loops :p

JASS:
for IceFCastLoop = 0 to 4
    // do stuffs...
endfor
Also another question is setting variables to null the same thing as a leak removal in gui?
Like "set pointvariable = null" is actually the function of "call RemoveLocation"?
No, you still have to use RemoveLocation if you use locations.
Try to use co-ordinates only, they are must more efficient.
Like call SetUnitX(u, 0.0).

You must set local variables that are handles to null (like unit, player, location etc.) at the end of the function.
A tip: you can use shorter variable names, because locals are only visible to that function they are in.

What Radamantus was saying:
JASS:
set IceFCastPointB = PolarProjectionBJ(IceFCastPointA, 20.00, (72.00 * I2R(GetForLoopIndexA())))
^^^ In this line you use GetForLoopIndexA() instead of IceFCastLoop.
 
Status
Not open for further replies.
Top