Hi,

I'm setting up anywhere between 1 and 20 arrays that I'm using to hold spawn and release times on my map.

Example:

var Wave1 = ["MapName",
	"delay", 1000,
	1,  3,
	"delay", 4000,
	1, 2,
	"end", 0
]

var Wave2 = ["MapName",
	"delay", 1000,
	1,  3,
	"delay", 4000,
	1, 2,
	"end", 0

]

And so forth ... could be up to 25 - 30 waves. The little hiccup I'm having is cleanup related. I need a way to access these arrays in a loop without having to cycle each array name pointer.

Wave1 = null Wave2 = null Wave3 = null .. . so forth..

I want to be able to access these arrays with a variable pointer but I havent found a way yet.

var Wave.1
var Wave(1)
var "1".Wave

etc.. am I missing something here?

thanks.

So having separate arrays like this is not a good design and not flexible. So I would not recommend it. But to answer your question, you can do it like this (but please don't do this):

var wave_array = get("Wave" + str(1))

A better way is to store the whole thing in a Dictionary. Dictionaries can store Arrays as well as other Dictionaries. So you can put everything in one structure.

var Waves = {1 : ["MapName",
        "delay", 1000,
        1,  3,
        "delay", 4000,
        1, 2,
        "end", 0],
2 :  ["MapName",
        "delay", 1000,
        1,  3,
        "delay", 4000,
        1, 2,
        "end", 0]}

Then you can access it like this:

var wave_1_array = Waves[1]

However, that is still a bad design, and I'm not sure why you are storing the values as loose values in an array. This is very rigid, and if you decided to change anything, or need another value in the middle, you will have to rewrite all your code. It's not very flexible. You want to use a Dictionary (similar to JSON in Javascript) to store your values.

var Wave1 = {
    "name" : "level_1"
    "delay" : 1000,
    "end": 0
}

That way every value has a name. Then access it like this:

var wave_1_delay = Wave1.delay

That said, the best way would be to define your own custom structure (class) to store the wave data. That way you don't have 25 arrays at the top of your script. You can also store the data in text files, like .csv files, which are loaded into the class instances. But this is rather advanced, and I won't explain it cause it would be pretty long, but that would be the correct way to do it.

Your insight is always helpful. Thank you very much, I'm going to go the class script method.

10 months later