1. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    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. Squiggy

    Squiggy

    Joined:
    Mar 25, 2008
    Messages:
    2,627
    Resources:
    18
    Maps:
    2
    Spells:
    15
    Tutorials:
    1
    Resources:
    18
    So, dear community

    I stumbled upon a spellthread which also stated that people should avoid using Integer A for loops in gui

    The reason for this was that there'd be a low probability that it 'bugs'
    The fact that they 'bug' (overlap in this case and run one time too much) seemed strange, so I put this trigger
    • loop
      • Events
        • Time - Every 0.05 seconds of game time
      • Conditions
      • Actions
        • For each (Integer A) from 1 to 10, do (Actions)
          • Loop - Actions
            • Set int = (int + 1)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • int not equal to (!=) 10
          • Then - Actions
            • Game - Display to (All players) the text: |cffff0000OMG U R R...
            • Set point = (Center of (Playable map area))
            • Unit - Create 1 Soldat for Player 1 (Red) at point facing default building degrees
            • Custom script: call RemoveLocation(udg_point)
          • Else - Actions
        • Set int = 0

    (the original trigger is this*8)
    and copied it a couple of times.
    Running warcraft after like 20 minutes showed me this(I removed the call BJDebugMsg):
    Click me
    [​IMG]

    which is quite a proof that the int never turned 11 and therefore no units were created, means Integer A does not bug or overlap or run too often.

    If you want to test this for yourself, I uploaded a version of the testmap as attachment - copy the triggers if you want.
     

    Attached Files:

    Last edited: Jul 17, 2009
  2. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,952
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    Why would it bug?
     
  3. Squiggy

    Squiggy

    Joined:
    Mar 25, 2008
    Messages:
    2,627
    Resources:
    18
    Maps:
    2
    Spells:
    15
    Tutorials:
    1
    Resources:
    18
    I was told that it MIGHT bug if two loops interfere with each other but the actual ''reason'' for this is unknown - I'd surely apprechiate it if the inveltor of this theory told me :)
     
  4. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    The actual reason is because (Integer A) is a global so two loops running it at once interfere with one another as they both access it and change it at the same time (more accurately, one changes it while the other is waiting for the first to finish).
     
  5. tml616

    tml616

    Joined:
    Apr 30, 2009
    Messages:
    337
    Resources:
    0
    Resources:
    0
    So (Integer A) is just like any global integer we would make for loops but with a built in (set A = A+1) at the end of the loop?
     
  6. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    No. It's built in to the loop construct.

    --

    (Integer A) is the global variable
    bj_forLoopAIndex
    .
     
  7. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,952
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    That's not a bug, that's bad coding. It seems like Squiggy was told about real bugs.
     
  8. Mooglefrooglian

    Mooglefrooglian

    Joined:
    Nov 28, 2008
    Messages:
    701
    Resources:
    0
    Resources:
    0
    Forgive me, but don't triggers NEVER run at the same time, therefore nulling the possibility of globals overlapping?
     
  9. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,952
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
  10. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Yes, but that doesn't mean one can't interrupt the other.
     
  11. Kwah

    Kwah

    Joined:
    May 9, 2007
    Messages:
    3,391
    Resources:
    8
    Icons:
    5
    Maps:
    1
    Tutorials:
    2
    Resources:
    8
    As far as I can see, these never collide.
     
  12. Mooglefrooglian

    Mooglefrooglian

    Joined:
    Nov 28, 2008
    Messages:
    701
    Resources:
    0
    Resources:
    0
    Could you clarify on that? If no two triggers will ever be executing at the same time - they wait for one another, unless theres a wait, correct? Shouldn't that mean that if there is no wait they would never be using the same global at the same time? Therefore never interrupting?
     
  13. Sophismata

    Sophismata

    Joined:
    Jul 17, 2009
    Messages:
    27
    Resources:
    0
    Resources:
    0
    Say you have a specific unit that has a UnitTakesDamage event. When the unit takes damage, an Integer A loop runs and causes that unit to damage a random nearby enemy unit A times for half the damage originally taken.

    Now, you have a spell with an Integer A loop that somehow deals damage to this specific unit during the loop. The spell thread is interrupted while the damage trigger runs, which also uses Integer A. You now have a conflict.

    This example may be a bit more complicated than it needs to be, but I tried to present a situation that someone might actually code.
     
  14. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,220
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Everything is in a order loop, while a loop must be ended before another one starts.
    Even if the other thing is at the same time, the computer have to calculate after each other, so there is no collision at all.
     
  15. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,952
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    Oh yes, there is. Ever heard of multithreaded tasks (it is said that ExecuteFunc and all his friends start a thread, don't ask me if it's right)?

    And another thing is (which I assume PurplePoot meant to say):
    • For (Integer A) do bla bla
      • ...
      • For (Integer A) do bla bla 2
        • ...
     
  16. Vulcano

    Vulcano

    Joined:
    Mar 8, 2009
    Messages:
    335
    Resources:
    1
    Maps:
    1
    Resources:
    1
    people just say it bugs because they have 2 loops with Integer A and then put a wait in one of the loops. It would also bug with any other global var.

    EDIT: I just thought of a trigger with a loop that took 5 seconds to complete, but while it was doing the loop no other triggers were excuted (normally a trigger should loc camera but i could just move screen). In short, i don't think loops without wait can interfere with each other.
     
  17. Sophismata

    Sophismata

    Joined:
    Jul 17, 2009
    Messages:
    27
    Resources:
    0
    Resources:
    0
    Odd. I posted an answer, but it's not showing up.

     
  18. Ciebron

    Ciebron

    Joined:
    Apr 6, 2008
    Messages:
    760
    Resources:
    2
    Spells:
    2
    Resources:
    2
    just do a "jass loop" with custom scripts and a local integer
     
  19. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,220
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    I can't see why this topic is useful at all.
    I mean its one of the basics of wc3, what do you think?
    It will NEVER fail, because else wc3 would have even more bugs.
    The loop is a well programed thing.
     
  20. Squiggy

    Squiggy

    Joined:
    Mar 25, 2008
    Messages:
    2,627
    Resources:
    18
    Maps:
    2
    Spells:
    15
    Tutorials:
    1
    Resources:
    18
    It's merely a clarification to avoid the misleading of new users because some were told that they had to avoid it which is wrong