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

[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