Wow it’s been so long… (and I still seem to stumble across the same problems
)
Here’s the deal. I am working on a game and I want to have the layout of the levels in textfiles.
Each textfile is named “level(n).txt” - where (n) is the number of the level (“level1.txt”, “level2.txt”, etc).
The level-“data” in those files is simply several rows of comma-seperated values that describe what kind of tile to use at that position. So typically, it would look something like this:
100,100,200,300,100
100,200,200,200,100
100,300,200,100,100
(and so on - you get the idea)
My question is, how do I use just one loadVars-function together with a loop (other ideas are welcome) to retrieve the data… and be able to tell which data the function is currently loading?
I used to do it like this:[LIST=1]
[]set a variable (on _root) as a “distinguisher” of the level number that is currently loaded
[]load the first level (with a timed call to the function with “setInterval”)
[]assign the retrieved data, if successfully loaded (with the “onLoad” even function)
[]upon recurrence of the Interval, check if data was assigned (or if assigning failed) and…
[*]load next level … [rinse, repeat][/LIST]My question now really is (without further ado):
Can’t I just call the “onLoad” function for the “loadVars” in a loop so it kind of loads all levels at once? If so, how does the function know which level it just loaded?
Or am I doing something wrong?
Here’s how I’d like it to work… but it’s probably even simpler than this:
gamedata_Arr:Array = Array();
distributeValues = function(success) {
if (success) {
// assign the data (that was loaded) to "gamedata_Arr",
// Array-Key = Level Number (how?)
}
}
levelValues = new LoadVars();
levelValues.onLoad = distributeValues;
// The loop to loadeverythingatonce (whee!)
loadLevels = function(howmanylevels) {
for (var ln = 1; ln <= howmanylevels; ln++) {
var filename:String = "level"+ln+".txt";
levelValues.load(filename);
}
}
loadLevels(3);
Yea… I’m lost… any way to help me? 