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

[Solved] How do I refer to Integer A in a custom script?

Status
Not open for further replies.
Level 5
Joined
May 20, 2008
Messages
138
Searched around a bit but didn't find it. Maybe I'm an idiot. I'm trying to do this, but it gives me a compile error. Obviously I need to write something else than "Integer A" within the square brackets.

  • For each (Integer A) from 1 to GEN_INTEGER_1, do (Actions)
    • Loop - Actions
      • Custom script: set udg_GEN_TEMP_UNIT_array[Integer A] = null
 
Last edited by a moderator:
Level 5
Joined
May 20, 2008
Messages
138
bj_forLoopAIndex
In your case:
  • For each (Integer A) from 1 to GEN_INTEGER_1, do (Actions)
    • Loop - Actions
      • Custom script: set udg_GEN_TEMP_UNIT_array[bj_forLoopAIndex] = null

Thanks!

tbh it is recommended to use your own integer variable for loops instead of Integer A or B.
Also, I think it is "GetForLoopIndexA()"

  • For each (Integer GEN_INTEGER_2) from 1 to GEN_INTEGER_1, do (Actions)
    • Loop - Actions
      • Custom script: set udg_GEN_TEMP_UNIT_array[udg_GEN_INTEGER_2] = null
Like this?
 
  • For each (Integer GEN_INTEGER_2) from 1 to GEN_INTEGER_1, do (Actions)
    • Loop - Actions
      • Custom script: set udg_GEN_TEMP_UNIT_array[udg_GEN_INTEGER_2] = null
Like this?

Yes. The reasoning behind it is that you may end up triggering a different event by accident, and the value of Integer A or Integer B might change. By using a separate variable for each loop, you can avoid that possibility.

Here is an example of a loop that would end up being messed up:
  • For each (Integer A) from 1 to 10, do (Actions)
    • Loop - Actions
      • Unit - Order (Triggering unit) to Stop
  • Stop Trigger
    • Events
      • Unit - A unit is issued an immediate order
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 20, do (Actions)
        • Loop - Actions
          • Game - Display "Hello" to (All players)
Due to the order of execution in Warcraft III, the order will issue -> "stop trigger" will fire -> run all actions of "Stop Trigger" -> then return to the first loop. Because of this, (Integer A) will end up as "20", and then it will return to the first loop as "20". Instead of running 10 times, the first loop will run once and then end. By using a separate variable for each of them, you can avoid that issue.
 
Status
Not open for further replies.
Top