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 havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. 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] How to exit loop?

Discussion in 'Triggers & Scripts' started by SupremeGrandRuler, Jul 22, 2012.

  1. SupremeGrandRuler

    SupremeGrandRuler

    Joined:
    Jun 24, 2012
    Messages:
    112
    Resources:
    0
    Resources:
    0
    I want 2 different exit loop functions:

    exitwhen Picked Unit has Buff[Integer A]
    exitwhen MyBoolean = True

    I'm not sure how to do it though. Any help appreciated :)
     
  2. KhaosMachine

    KhaosMachine

    Joined:
    Dec 30, 2011
    Messages:
    117
    Resources:
    6
    Spells:
    6
    Resources:
    6
    exitwhen = if

    An example:

    Code (vJASS):

    local integer i = 0
    local boolean exit = false
    loop
        exitwhen i >= 10 or / and exit
        set exit = GetUnitAbilityLevel(XUnit, XAbility) > 0
        set i = i + 1
    endloop
     
     
  3. SupremeGrandRuler

    SupremeGrandRuler

    Joined:
    Jun 24, 2012
    Messages:
    112
    Resources:
    0
    Resources:
    0
    I tried that first but it's not working for me.
     
  4. defskull

    defskull

    Joined:
    Mar 27, 2008
    Messages:
    7,979
    Resources:
    17
    Spells:
    17
    Resources:
    17
    From what I understand;
    I believe you should use OR function, right ?
    Either condition should be fine, exit loop either your picked unit has buff, or your Boolean is equal to True.

    Or the other way around ?
    Both must be true ? (Picked unit has buff + Boolean is True) ?
     
  5. SupremeGrandRuler

    SupremeGrandRuler

    Joined:
    Jun 24, 2012
    Messages:
    112
    Resources:
    0
    Resources:
    0
    No, no seperate. Each is for different loops.
     
  6. defskull

    defskull

    Joined:
    Mar 27, 2008
    Messages:
    7,979
    Resources:
    17
    Spells:
    17
    Resources:
    17
    So you mean each condition is not meant for each other ?
    So this is somewhat 2 separate function, eh ?

    If you want to check a certain condition over-time, direct loop is never the answer.

    You should use the Event Time - Periodic Event so that you can evaluate the condition each time.

    The method you currently used is a direct looping which checks the condition for several times (but in a single period) where you should constantly checking the condition, that's why we use that Event.

    Let's say we take a 0.10 second of Periodic Time event.

    So, each 0.10 second pass, you make a check, this way you will evaluate those conditions per 0.10 second.
     
  7. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,722
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    There is no limit to the number of "exitwhen" clauses a loop can have in WarCraft III.

    In programming languages like C this is obtained by using the "break" statement (which JASS does not have). The use is to allow early exits from complex loops without having to reach the end.

    In simple loops you can often tie the logic together using the logical "and" and "or" operators.
     
  8. SupremeGrandRuler

    SupremeGrandRuler

    Joined:
    Jun 24, 2012
    Messages:
    112
    Resources:
    0
    Resources:
    0
    Yes.

    Basically, when a unit is struck by a projectile, I need to check if the unit has a buff on, then exit the loop as soon as a buff is found.
     
  9. defskull

    defskull

    Joined:
    Mar 27, 2008
    Messages:
    7,979
    Resources:
    17
    Spells:
    17
    Resources:
    17
    Did you even read my post below that ?
     
  10. SupremeGrandRuler

    SupremeGrandRuler

    Joined:
    Jun 24, 2012
    Messages:
    112
    Resources:
    0
    Resources:
    0
    Yes. It wouldn't work for what I'm doing.
     
  11. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Posting some code for the others would be nice. (If you want to)