• 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.

[JASS] Variable index in array element asssignment

Status
Not open for further replies.
Level 2
Joined
Aug 21, 2010
Messages
17
Is it possible to use a variable index when using the set array function to assign a value to an array cell? For example:

JASS:
	local integer i = 0
	loop
		exitwhen(i == 10)
		set element[i] = //something
	endloop
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
yes, but you are lacking one thing:
JASS:
set i = i + 1
you have to do the increment yourself, so it looks like:
JASS:
local integer i = 0
loop
    set element[i] = ...
    exitwhen i == 10
    set i = i + 1
endloop

also be vary that the game leaves the loop at point of exitwhen so if you want the element's index 10 you need to either make the exitwhen i == 11 or move element assigment above exitwhen
 
Level 2
Joined
Aug 21, 2010
Messages
17
I know thanks, it's like a while-do. No problem with that. I just wanted to know if you could use a variable index, because for example some stuff you can do in programming languages are not allowed in plain JASS, such as passing an array as function argument.
 
Status
Not open for further replies.
Top