[JASS] Custom Script: How to exit loop when...?

Level 6
Joined
Jul 8, 2008
Messages
150
How can I exist a loop when Ability_Cast = Ability_Learn[Ability_Integer]

This is what I have right now:

  • Allocating Skills
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • ((Triggering unit) is A Hero) Equal to True
          • Ability_Points[(Player number of (Owner of (Triggering unit)))] Greater than or equal to 1
    • Actions
      • Set Ability_Cast = (Ability being cast)
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set Ability_Integer = (Integer A)
          • Custom script: exitwhen (GetAbilityId(_udg_Ability_Cast) == udg_Ability_Learn[udg_Ability_Integer])
I get error "Expected a name"
 
Level 8
Joined
Feb 15, 2009
Messages
463
The problem is you already have exitwhen and this is the loop 1-12 you need another custom script which is a new loop
do it with
custom script :loop (yeah just loop ) before the variable setting in the loop

also make what justify old you
 
Level 8
Joined
Feb 15, 2009
Messages
463
i cant post it but your code would like in jass like about this
JASS:
loop
exitwhen exitwhen loop_integer _a > loop_integer_b( or 12)
set a = a+1
your actions
exitwhen your exitwhen
endloop
you see the point ? and i gave you a solution =D just make another loop there in your case with custom scripts =D
JASS:
loop
    exitwhen loop_integer _a > loop_integer_b( or 12)
    set a = a+1
        loop // this is a new requirement do it with custom script
             your actions  //**
             exitwhen - your exitwhen   //**
        endloop// this is a new requirement do it with custom script
endloop
 
Level 6
Joined
Jul 8, 2008
Messages
150
i cant post it but your code would like in jass like about this
JASS:
loop
exitwhen exitwhen loop_integer _a > loop_integer_b( or 12)
set a = a+1
your actions
exitwhen your exitwhen
endloop
you see the point ? and i gave you a solution =D just make another loop there in your case with custom scripts =D
JASS:
loop
    exitwhen loop_integer _a > loop_integer_b( or 12)
    set a = a+1
        loop // this is a new requirement do it with custom script
             your actions  //**
             exitwhen - your exitwhen   //**
        endloop// this is a new requirement do it with custom script
endloop

The problem is that I'm trying to exit the loop at a certain time and I don't know how to exit a loop when the ability cast is = to ability[X].
 
Level 13
Joined
Mar 16, 2008
Messages
943
Its not forbidden to have multiple "exitwhen" in the same loop and there isn't a reason why it should be...
The problem is "GetAbilityId"... this function doesn't exist, at least I never heard of it and JassCraft doesn't "know" it too
I bet you're searching for "GetSpellAbilityId" :)

@Saia_Djinn: Please stop posting stuff when you don't know what you're talking about :/ exitwhen only stops the current loop and not the ones "above" it, so your idea can't work...
 
Level 6
Joined
Sep 5, 2007
Messages
264
You'd also be (only slightly) better off using:
JASS:
exitwhen (udg_Ability_Cast == udg_Ability_Learn[bj_forLoopAIndex])
and forget the udg_Ability_Integer variable all together.

It's only 1 CPU cycle per loop, but, it's a good practice to look for faster ways to do things... especially once you move on to more complex things.

EDIT:
@Lightstalker: Just looking over that script of yours, shouldn't "triggering unit" be "casting unit"?
 
Level 6
Joined
Jul 8, 2008
Messages
150
You'd also be (only slightly) better off using:
JASS:
exitwhen (udg_Ability_Cast == udg_Ability_Learn[bj_forLoopAIndex])
and forget the udg_Ability_Integer variable all together.

It's only 1 CPU cycle per loop, but, it's a good practice to look for faster ways to do things... especially once you move on to more complex things.

EDIT:
@Lightstalker: Just looking over that script of yours, shouldn't "triggering unit" be "casting unit"?

Could I? I heard bjs were bad, but if they're not I'll just use that. Much easier than making an integer.
 
Level 6
Joined
Sep 5, 2007
Messages
264
When being told to avoid BJ's, it's in reference to BJ functions that just call other functions (wasting CPU time and lowering performance). That BJ I gave you is the JASS equivilant of "Integer A" in GUI. It is a direct reference to the variable, and would gain you CPU time (as stated earlier, only 1 cycle per loop. But, it can add up). The way you did it was, simply put:
JASS:
udg_Ability_Integer = bj_forLoopAIndex
exitwhen (udg_Ability_Cast == udg_Ability_Learn[udg_Ability_Integer])

My way:
JASS:
exitwhen (udg_Ability_Cast == udg_Ability_Learn[bj_forLoopAIndex])

I skip the useless "udg_Ability_Integer = bj_forLoopAIndex"... you don't need it, just access what udg_Ability_Integer is pointing to directly. In a way, you'd created your own mini BJ.

Hope this helps you understand what I meant :thumbs_up:
 
Top