• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[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