1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The reforging of the races is complete. Come see the 14th Techtree Contest Results.
    Dismiss Notice
  4. It's time to choose your horse in the race - the 32nd Modeling Contest Poll is up!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

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

Discussion in 'Triggers & Scripts' started by Lightstalker, May 10, 2009.

  1. Lightstalker

    Lightstalker

    Joined:
    Jul 8, 2008
    Messages:
    150
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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"
     
  2. Justify

    Justify

    Joined:
    Mar 16, 2008
    Messages:
    935
    Resources:
    5
    Models:
    1
    Icons:
    1
    Spells:
    3
    Resources:
    5
    _udg_Ability_Cast

    try it without this^^
     
  3. Lightstalker

    Lightstalker

    Joined:
    Jul 8, 2008
    Messages:
    150
    Resources:
    1
    Maps:
    1
    Resources:
    1
    still get the error.
     
  4. Saia_Djinn

    Saia_Djinn

    Joined:
    Feb 15, 2009
    Messages:
    458
    Resources:
    0
    Resources:
    0
    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
     
  5. Lightstalker

    Lightstalker

    Joined:
    Jul 8, 2008
    Messages:
    150
    Resources:
    1
    Maps:
    1
    Resources:
    1
    What do you mean I already have exitwhen? Can you post a quick trigger please :grin:
     
  6. Saia_Djinn

    Saia_Djinn

    Joined:
    Feb 15, 2009
    Messages:
    458
    Resources:
    0
    Resources:
    0
    i cant post it but your code would like in jass like about this
    Code (vJASS):

    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
    Code (vJASS):

    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
     
     
  7. Lightstalker

    Lightstalker

    Joined:
    Jul 8, 2008
    Messages:
    150
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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].
     
  8. Justify

    Justify

    Joined:
    Mar 16, 2008
    Messages:
    935
    Resources:
    5
    Models:
    1
    Icons:
    1
    Spells:
    3
    Resources:
    5
    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...
     
  9. Saia_Djinn

    Saia_Djinn

    Joined:
    Feb 15, 2009
    Messages:
    458
    Resources:
    0
    Resources:
    0
    Edit oh yes your right justify just forget my trassh talk sry
     
  10. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,872
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    If you don't know what you're talking about, better be silent.
     
  11. Lightstalker

    Lightstalker

    Joined:
    Jul 8, 2008
    Messages:
    150
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Code (Text):
    Custom script:   exitwhen (GetSpellAbilityId(udg_Ability_Cast) == udg_Ability_Learn[udg_Ability_Integer])
     
    I get "invalid number of arguments" now :(
     
  12. Mechanical Man

    Mechanical Man

    Joined:
    Jan 18, 2005
    Messages:
    5,384
    Resources:
    39
    Models:
    30
    Icons:
    3
    Packs:
    1
    Maps:
    4
    Tutorials:
    1
    Resources:
    39
    Use a variable isntead of A or B and set that variable to the max number when the condition is set.
     
  13. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    GetSpellAbilityId() takes no parameters. It's basically jass for "Ability being cast"

    I think what you're looking for is this:
    exitwhen (udg_Ability_Cast == udg_Ability_Learn[udg_Ability_Integer])
     
  14. Lord_BoNes

    Lord_BoNes

    Joined:
    Sep 5, 2007
    Messages:
    264
    Resources:
    0
    Resources:
    0
    You'd also be (only slightly) better off using:
    Code (vJASS):

    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"?
     
  15. Teelo

    Teelo

    Joined:
    Mar 31, 2009
    Messages:
    709
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Couldn't you just use:
    • Trigger - Skip remaining actions
     
  16. Justify

    Justify

    Joined:
    Mar 16, 2008
    Messages:
    935
    Resources:
    5
    Models:
    1
    Icons:
    1
    Spells:
    3
    Resources:
    5
    This doesn't stop a loop but the entire trigger, and that's not what he wants
     
  17. Lightstalker

    Lightstalker

    Joined:
    Jul 8, 2008
    Messages:
    150
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Could I? I heard bjs were bad, but if they're not I'll just use that. Much easier than making an integer.
     
  18. Lord_BoNes

    Lord_BoNes

    Joined:
    Sep 5, 2007
    Messages:
    264
    Resources:
    0
    Resources:
    0
    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:
    Code (vJASS):

    udg_Ability_Integer = bj_forLoopAIndex
    exitwhen (udg_Ability_Cast == udg_Ability_Learn[udg_Ability_Integer])
     


    My way:
    Code (vJASS):

    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: