I'm having issues figuring out my nested data structures. I keep receiving errors. I apologize for the wall of text here...
Long story short, what this is trying to do:
I have tons of o_stageBlocks (obj) that I place over parts of a level to piece them together randomly. I then use the with command to retrieve any objects overlapping them, get all the tile data, and put them to the appropriate list/grids in the constructors. Then upon room start, I create a random list of the rooms, and in order build the stage from these bits. The tiles load perfectly, and honestly when I was NOT using a map and instead used a struct, everything was fine. I then realized that a map would give me more flexibility (hence the switchover)
ROOM START EVENT
This part of the code works. Each "worldDataBlob" is saved to a ds_list on this particular object. I can check the references of worldDataBlob.objBlob[| int][? KEY] and I get the correct result for all objects. I then add the worldDataBlob struct to a list on the object called orderedList.
This is where I start to get errors:
ROOM START (I'm on purpose hiding needless room check code)
Now, this SHOULD loop through each object in the constructor's list that was saved, retrieve the map and use all the correct variables. For some reason, looking at the debugger, I see this:
orderedList (list of structs (worldDataBlobs)) > structs (list, 2 grids, and a variable or two) > list of entries (all have value 22 in debugger), within the list, if I try to view as ds_map (which is what it should be) it says size =-1 invalid structure. However, if I view as a list, EVERY entry has a ds_list_size of 2, the first position(0) being empty, and the 2nd (1) being a map (however the values look incredibly strange - the key is 32098 or some number like that and the value is seemingly 0-22). Somehow this tells me something is wrong in the creation code, but I can't find what it is.
I'm sure it's as simple as a line being in the wrong bracket, but I cannot, for the life of me, figure it out. The actual code for this is much larger than this, I'm just trying to cut out the extra code to needlessly look at.
Any ideas?
Long story short, what this is trying to do:
I have tons of o_stageBlocks (obj) that I place over parts of a level to piece them together randomly. I then use the with command to retrieve any objects overlapping them, get all the tile data, and put them to the appropriate list/grids in the constructors. Then upon room start, I create a random list of the rooms, and in order build the stage from these bits. The tiles load perfectly, and honestly when I was NOT using a map and instead used a struct, everything was fine. I then realized that a map would give me more flexibility (hence the switchover)
ROOM START EVENT
GML:
with(o_stageBlock)
{
// this is a constructor that creates a couple grids and a list for objects (worldDataBlob.objBlob is a ds_list initiated in the constructor)
var worldDataBlob = new createWorldBlob([0,0],[0,0],[0,0]);
#region OBJECT DATA
var objs = ds_list_create();
var num = instance_place_list(x,y,all,objs,false);
var ignoreObject = [o_stageBlockLeft, o_stageBlockRight];
if (num > 0)
{
// loop through all objects
for (var i=0;i<num;i++)
{
var item = objs[| i];
// makes sure to not include specific objects in array (function that returns true or false if object is found in array)
if (!in_array(item.object_index,ignoreObject))
{
var map = ds_map_create();
ds_map_add(map,"x",abs(startBlock.x - item.x));
ds_map_add(map,"y",item.y - startBlock.y);
ds_map_add(map,"xscale",item.image_xscale);
ds_map_add(map,"yscale",item.image_yscale);
ds_map_add(map,"index",item.object_index);
ds_map_add(map,"angle",item.image_angle);
ds_map_add(map,"layer",layer_get_name(item.layer));
// OBJ SPECIFIC ONCREATE VARIABLES
switch(item.object_index)
{
case o_portal: ds_map_add(map,"type",item.type); break;
}
ds_list_add(worldDataBlob.objBlob, map);
//show_message(worldDataBlob.objBlob[| index][? "x"]);
//ds_list_mark_as_map(worldDataBlob.objBlob,i);
ds_map_destroy(map);
}
}
// adds this list of maps to the objBlob list
//ds_list_add(worldDataBlob.objBlob,map);
}
ds_list_destroy(objs);
#endregion
}
This is where I start to get errors:
ROOM START (I'm on purpose hiding needless room check code)
GML:
// this list is created in a very long function that I'm not going to put here - I've confirmed it works
var amt = ds_list_size(orderedList);
// loop through each selected blob choice and create the final map
for (var a=0;a<amt;a++)
{
// current room chosen
var curIndex = orderedList[| a];
#region CREATE OBJECTS
for (var i=0;i<ds_list_size(curIndex.objBlob);i++)
{
var item = curIndex.objBlob[| i];
var _obj = item[? "index"];
var _x = item[? "x"];
var _y = item[? "y"];
var _layer = item[? "layer"];
var obj = instance_create_layer(_x,_y,_layer,_obj);
obj.image_xscale = item[? "xscale"];
obj.image_yscale = item[? "yscale"];
obj.image_angle = item[? "angle"];
}
#endregion
orderedList (list of structs (worldDataBlobs)) > structs (list, 2 grids, and a variable or two) > list of entries (all have value 22 in debugger), within the list, if I try to view as ds_map (which is what it should be) it says size =-1 invalid structure. However, if I view as a list, EVERY entry has a ds_list_size of 2, the first position(0) being empty, and the 2nd (1) being a map (however the values look incredibly strange - the key is 32098 or some number like that and the value is seemingly 0-22). Somehow this tells me something is wrong in the creation code, but I can't find what it is.
I'm sure it's as simple as a line being in the wrong bracket, but I cannot, for the life of me, figure it out. The actual code for this is much larger than this, I'm just trying to cut out the extra code to needlessly look at.
Any ideas?