- Joined
- Mar 6, 2006
- Messages
- 282
So I'm learning JASS, and I don't understand how to do something.
With bj_forLoopAIndex as a loop iterator, you can call a function from your loop and use bj_forLoopAIndex in the called function. But people say not to use global loop iterators. So how can you use a local iterator and use it in a function that the loop calls?
For example, this would be an MUI spell for an ability called Punch. The called function is Knockback, and it needs to know who is punching.
(this is kind of a 2nd question)
If GUI uses bj_forLoopAIndex for loops, then how can you have 2 loops going at the same time, and they don't change each other's bj_forLoopAIndex ??
With bj_forLoopAIndex as a loop iterator, you can call a function from your loop and use bj_forLoopAIndex in the called function. But people say not to use global loop iterators. So how can you use a local iterator and use it in a function that the loop calls?
For example, this would be an MUI spell for an ability called Punch. The called function is Knockback, and it needs to know who is punching.
JASS:
function Knockback takes nothing returns nothing
UnitDamageTarget( Hero[bj_forLoopAIndex], target, 999 dmg)
endfunction
function Punch takes nothing returns nothing
set bj_forLoopAIndex = 0
loop
exitwhen bj_forLoopAIndex > 11
if udg_HeroIsPunching[bj_forLoopAIndex] then
set mygroup = GetPunchableUnits()
ForGroup(mygroup, Knockback() )
endif
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
endfunction
(this is kind of a 2nd question)
If GUI uses bj_forLoopAIndex for loops, then how can you have 2 loops going at the same time, and they don't change each other's bj_forLoopAIndex ??