• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Integer A does not bug

Status
Not open for further replies.
Level 28
Joined
Mar 25, 2008
Messages
2,955
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):
5917390211077730282200944.jpg

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.
 

Attachments

  • test.w3x
    18.2 KB · Views: 54
Last edited:
Level 8
Joined
Apr 30, 2009
Messages
338
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?
 
Level 9
Joined
Nov 28, 2008
Messages
704
Yes, but that doesn't mean one can't interrupt the other.

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?
 
Level 2
Joined
Jul 17, 2009
Messages
27
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.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
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
      • ...
 
Level 7
Joined
Mar 8, 2009
Messages
360
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.
 
Level 2
Joined
Jul 17, 2009
Messages
27
Odd. I posted an answer, but it's not showing up.

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.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
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?
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.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
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.
 
Level 9
Joined
Nov 28, 2008
Messages
704
So to summarize, it is cocded to run only one trigger at a time in a huge line. Any new trigger called will interrupt the first one, putting it to sleep until the new trigger is done or has its own wait. Waits are shoved to the back of the line depending on how long they have left.

Is that how it works, or what?
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
I was proving the exact opposite in my first post

Unless you don't use nested loops and/or waits, you're fine

I have to put in my word here:

No one said that Integer A/B bugs ALL THE TIME when there loops are running at the same time.

The chance is pretty low of my experience since I used it alot before.

Squggy your example is not enough cause the same trigger copied is wrong, try many different triggers with different periodic events and other events that happens at the same time and you will see my point.

Even thought I get your point with the loops. It takes less then nano seconds to execute these loops and the chance that they overlap should be LOW enough to be use able but if you have like 50 spells with periodics and only using int A and mostly casted all around the game it will prob bug.

~baassee
 
Status
Not open for further replies.
Top