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. Dismiss Notice
  4. 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
  5. Dismiss Notice
  6. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  7. 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.

Integer A does not bug

Discussion in 'Triggers & Scripts' started by Squiggy, Jul 17, 2009.

  1. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,193
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Avoid the most working function in wc3? Lol.
     
  2. Squiggy

    Squiggy

    Joined:
    Mar 25, 2008
    Messages:
    2,619
    Resources:
    18
    Maps:
    2
    Spells:
    15
    Tutorials:
    1
    Resources:
    18
  3. Pharaoh_

    Pharaoh_

    Joined:
    Nov 6, 2008
    Messages:
    8,127
    Resources:
    11
    Icons:
    3
    Skins:
    1
    Spells:
    6
    Tutorials:
    1
    Resources:
    11
    Uh, indeed @Anachron & @Squiggy, everyone claims that Integer A is problematic, GetLocalPlayer() can crash the WC3 or give some bugs, Unit - Remove unit is an also problematic action... bla bla! How come i never had crashes, when using those functions, only God knows :D
     
  4. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,298
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    If your loop has waits in it, and another trigger executes while that trigger with a loop executes while that trigger is "sleeping", integer A would bugger up. I think this could even cause infinite loops.
     
  5. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,840
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    GetLocalPlayer() is a BIT more risky then this...
     
  6. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,298
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    Yeah. It desyncs. But only when used with functions which cause net traffic. IE most functions.
     
  7. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,193
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
  8. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,298
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    In JASS, it's easy - you use a local. In GUI, if you want to have waits in your loop, use your own variables, but otherwise, there is absolutely NO PROBLEM with Integer A / Integer B.
     
  9. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,193
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Agreed, quoted for truth and hopefully solved this.
     
  10. Squiggy

    Squiggy

    Joined:
    Mar 25, 2008
    Messages:
    2,619
    Resources:
    18
    Maps:
    2
    Spells:
    15
    Tutorials:
    1
    Resources:
    18
    Whoever uses jass, uses a local - but this is related to gui
     
  11. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    If you kill a unit, any triggers with A Unit Dies will interrupt the current thread rather than wait for it. The same goes for any other events or function calls.
     
  12. busterkomo

    busterkomo

    Joined:
    Jun 17, 2007
    Messages:
    1,423
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Putting any waits inside the loop will also cause it to completely malfunction.
     
  13. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,298
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    Not completely malfunction - just go wrong if another Integer A loop runs at the same time.
     
  14. busterkomo

    busterkomo

    Joined:
    Jun 17, 2007
    Messages:
    1,423
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Obviously.
     
  15. Deuterium

    Deuterium

    Joined:
    Mar 17, 2009
    Messages:
    1,301
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    Well, ok so simply use a local/struct variable/indexed global... I mean, in Jass that takes even less time to do. In GUI, meh an additional 5 seconds...
     
  16. Mooglefrooglian

    Mooglefrooglian

    Joined:
    Nov 28, 2008
    Messages:
    701
    Resources:
    0
    Resources:
    0
    Ah, so that's how the order goes. Thanks.
     
  17. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    It's called being a responsible coder.
     
  18. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    Ok explained in simple words:

    What happens is this:

    1. While (Integer A) < 10 Do:
    2. (Your actions)
    3. Set Integer A = Integer A + 1
    4. Repeat line 1

    A trigger can only be interrupted by a different trigger when a "Wait X seconds" action is used. Thus, if both triggers use Integer A, and a Wait action occurs inside the loop, then trigger A is interrupted, trigger B modifies Integer A, and then trigger A continues looping but this time with a modified Integer A. This is where the bugs happen. It is a very logical bug and oh-so-easily avoided with jass.

    Another bug occurs with nested loops, since both loops are modifying Integer A. For example:

    • While (Integer A) < 10 Do:
      • While (Integer A) < 5 Do:
        • Set Integer A = Integer A + 1
        • Repeat line 2
      • Set Integer A = Integer A + 1
      • Repeat line 1

    The bug is obvious: After 5 loops, the first (outer) loop will have modified Integer A to be larger than 5 but smaller than 10. Yet, the second loop requires it to be smaller than 5, and thus bugs occur.
     
  19. Deuterium

    Deuterium

    Joined:
    Mar 17, 2009
    Messages:
    1,301
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    Well PP, even if a unit dies, I don't think it interrupts the actions of one trigger, but maybe interrupt the queue of triggers to run... or am I wrong? (this is just an educated guess).
     
  20. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    You're wrong. Feel free to test it--this has been the subject of several annoying bugs in my code in the past, which is why I finally realized how this thing worked.