-
More level editor woes
Ah, my troubles seem neverending with this level editor of mine!
I just realized that in my level editor I'm only able to write one tile to every position.
As it is now, I'm saving a bunch of variables into an array that takes X,Y and Z into account.
X and Y are the positioning, and the Z contains info about what is placed. The problem is that it only reads the array once upon loading the level.
The only way I can see this working is if I save every layer to a separate array and load them one at a time, but that seems very extensive.
Antother solution would be to have an array within an array, but I can't see how that would work in this software.
Basically, I need to save the information about every grid, but have it stored in 7 Z dimensions representing all the layers that I use, so that each tile can have more than one tile on it, but on different layer levels.
Any ideas would be greatly appreciated!
-
Well, I solved this sort of. What I'm doing now is I'm saving 4 arrays per level
Array 1: Stores The layer of the object by the Z index,and the nature of the object as a string by the XYZ position, "Backdrop", "Obstacle" or "Active".
Array 2: Stores the frame id of the current position, at the same XYZ but in a different array. This is so that the Active object that is the backdrop placer will know which image to create a backdrop from.
Array 3: Stores the name of the active to be created if Array 1 returns "Active" in the current XYZ position. THis is done because there is a "Create by name" function, and it takes the input from the current XYZ of this array to decide what to create.
Array 4: Stores unique variables to active objects. For example, to link a switch and a door I will assign them both an unique id during the level editing phase, and when the level loads, they will get the property from XYZ of this array. the Z index indicates the position of the variable, if it is Alterable Varible A, B or C, while the value at the index indicates what the variable is to be set to.
Upon loading the level, I run the Z loop 7 times, once for each layer This is to make sure each object gets created at the proper layer. Throughout the rest of the loops, whenever a layer needs to be referenced, it is done by referring to LoopIndex(load_Z). Within the Z loop, I run the X loop for the entire width of the level, and within the X loop I run the Y loop for the length of the level. It is during the Y loop that the tiles are actually pasted into the level as backdrops. While 4 arrays is a bit much, I couldn't think of any other way to do it while still retaining control.
-
use one array, make it a string array.
think of each array cell on x and y as part of your grid: 0,0 is the top left of the grid, 0,1 is 1 tile down, etc. You save all the tile info to a string in a tile on the xy axis ("tile name, tile ID, tile collision type, etc"), then use the array's Z axis to determine what layer it is on. So a tile at 5,5 in the grid on layer 3 would be saved to Array(x5, y5, z3). To retrieve the tile info from your string, use the string tokenizer extension and split the string (1D) with a delimiter of ",", then retrieve the elements (0 is the first element, 1 the second and so on) to correctly set up your tile.
No need to store the tile's actual position in the array: whenever retrieving a tile from the array, you position it at your origin coordinates (usually 0,0 or something) then do
set position to
-->Origin point + (tile size * position on the grid (usually found using nested loops))
To position it in the world.
-
Hm, is it possible to concatenate strings in the Alterable Strings part? Like if I have a value that is currently "Object", can I add a string to it so that it becomes "Object, Tiletype"? and then separate them?
-
I noticed in the string tokenizer, is there a way to clear it? I want to refer to only index 0 and 1 of the string tokenizer, but as i read and split more strings, won't they add upp?
-
You can add to strings. What you need to do is set the string to itself + your new string: i.e "Object" + ", Tiletype" = "Object, Tiletype".
You can clear the elements by re-splitting the string. Every time you split the string it resets all the elements.