• 🏆 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!

Integrated Variables

Status
Not open for further replies.
Level 3
Joined
May 10, 2014
Messages
41
Hello!

I've got a very simple question...

Can be integrated variables (A, B) used several at one time in different triggers?
Does using A in one trigger affect A used in another?

How much time need game engine to perform simple "for each variable" cycle from 1 to 12?
Is there any delay in game? Or it's just depends of machine?

Thanks for any information! :as:
 
Integer A and Integer B are used for all GUI loops, so yes, they can interfere with each other. But it is rare for them to interfere; it is not as simple as you might think.

First things first, how does wc3 handle triggers that run "at the same time"? Let's say you have two triggers that run when a unit dies, trigger 1 and trigger 2. They both use an Integer A loop. Will they interfere? No. Why? In wc3, triggers don't actually run at the same time. There is always some order to it. So there are two possibilities:

Trigger 1 runs -> then trigger 2. OR
Trigger 2 runs -> then trigger 1.

So the loops won't interfere with each other. The GUI loop is set up so that it can be used multiple times throughout many triggers.

However, there is one case where using Integer A can cause problems. Let's say you have these triggers:
  • Trigger 1
    • Events
      • Time - 0.00 seconds elapsed (game-time)
    • Conditions
    • Actions
      • Game - Display text to (All players): "Killing..."
      • Unit - Kill Mountain King 0002 <gen>
      • Game - Display text to (All players): "Trigger 1"
  • Trigger 2
    • Events
      • Unit - A unit dies
    • Conditions
    • Actions
      • Game - Display text to (All players): "A unit died."
As you can see, trigger 1 will kill a unit, and that will cause trigger 2 to fire. But when does it fire? Well, test this out, and in what order will you receive the messages?

The answer: "Killing..." -> "A unit died." -> "Trigger 1"

What happened? Trigger 1 fired, and it killed the unit. Then trigger 1 paused its actions, jumped over to trigger 2, did those actions, and then it jumped back and resumed trigger 1 (to display the last message). Weird, huh? This is actually a very useful fact in a lot of cases, but it can also cause really weird problems. For example:
  • Trigger 1
    • Events
      • Time - 0.00 seconds elapsed (game-time)
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10 do (Actions)
        • Loop - Actions
          • Unit - Kill SomeUnitArray[(Integer A)]
  • Trigger 2
    • Events
      • Unit - A unit dies
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10 do (actions)
        • Loop - Actions
          • Game - Display text to player "lol"
This seems like a simple trigger setup. It looks like it should kill 10 units in some unit array named "SomeUnitArray". This will fire Trigger 2, which will display "lol" 10 times. As such, you should expect 100 game messages. But what really happens?

It turns out, you only kill SomeUnitArray[1], and "lol" is displayed only 10 times. What happened? Well, based on the rule described above, Trigger 1 killed SomeUnitArray[1] and jumped over to trigger 2. This loop ran (Integer A) from 1 to 10 to display "lol", so this brings Integer A up to 10! So when we jump back to Trigger 1, it finishes the loop immediately since we only designed the loop to run from 1 to 10.

This is a bit complicated to grasp, and it is a rare case, so it is up to you whether you want to worry about it. To fix it, most people will use their own custom integer variable for looping. You only need 1 separate variable per trigger (sometimes you can share them, but you should know what you're doing).

-----

TLDR; they may affect each other, but it is rare.

How much time need game engine to perform simple "for each variable" cycle from 1 to 12?
Is there any delay in game? Or it's just depends of machine?

It does depend on the machine, but you can consider it instant. Computers are amazingly fast, and a simple 12-iteration loop is really really easy for them. It can depend on the machine or what you're doing inside of the loop, but in most cases you should be fine. There won't be any delay, but if you're doing something really expensive (such as creating 1000 special effects) then there will be some framerate drop. The actual loop itself is incredibly cheap.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
Can be integrated variables (A, B) used several at one time in different triggers?
As far as I know WC3 does not support native discrete integration, you will have to use the mathematics taught in various mathematics/engineering courses at University to do so.

Yes you can use the same varibles in may triggers.

Does using A in one trigger affect A used in another?
If they are globals and the trigger uses them to retain non-instant information then yes.
 
Status
Not open for further replies.
Top