T
tomsaram
Guest
Hi,
So I have this dynamic data structure (say a list) of arrays in my game. And for whatever reason the accessors cannot stack on each other:
I have to instead use this alternative strategy to access the data:
Or use some kind of script trick:
Well my problem with strategy 1 is that it makes a copy of the array, which is obviously not the most efficient thing to do. Strategy 2 seems promising, but I am rather skeptical about it, because if something as simple as this would work, then I don't see why the accessors cannot stack in the first place.
So this is why I am considering to replace my arrays by instances, which are deactivated and is basically a vessel for the data. This allows for a much clearer syntax (methink):
So here is my first question: is any one of the three strategies significantly better (or worse) than the other two? Or are they equally pathetic, and there is a correct way to go by unbeknownst to me?
Lets say I use the instance strategy, and the instances need to be persistent. Since they are deactivated, they need to be activated before the room changes:
This looks reasonable at the first glance, by turns out to be problematic. This means that each and every objects / scripts that calls room_goto() would need this structure, and myDS is neither global nor local to the instance calling, there can even be more than one such data structures, which makes this structure very ugly.
Is there an elegant way to do this? I have already tried the room_end event, which does not work.
Any help or insight would be much appreciated.
P.S. I am using GMS 1.4, but to by best knowledge, GMS 2 has more or less the same behavior. I have only read through the manual so I may be very mistaken.
So I have this dynamic data structure (say a list) of arrays in my game. And for whatever reason the accessors cannot stack on each other:
Code:
myVar = myDS[| listIndex][arrayIndex]; // does not work
Code:
//strategy 1
var myArray;
myArray = myDS[| listIndex];
myVar = myArray[arrayIndex];
myArray = 0;
Code:
//strategy 2
///fetchElement(array, index)
return argument0[argument1];
//somewhere outside of the script
myVar = fetchElement(myDS[| listIndex], arrayIndex);
So this is why I am considering to replace my arrays by instances, which are deactivated and is basically a vessel for the data. This allows for a much clearer syntax (methink):
Code:
//strategy 3 - instances
myVar = myDS[| listIndex].data[arrayIndex];
myOtherVar = myDS[| listIndex].otherData; // data does not need to be an array
Lets say I use the instance strategy, and the instances need to be persistent. Since they are deactivated, they need to be activated before the room changes:
Code:
//This needs to be done
//whenever room changes
for (i = 0; i < ds_list_size(myDS), i++){
instance_activate_object(myDS[| i]);
}
room_goto(otherRoom);
Is there an elegant way to do this? I have already tried the room_end event, which does not work.
Any help or insight would be much appreciated.
P.S. I am using GMS 1.4, but to by best knowledge, GMS 2 has more or less the same behavior. I have only read through the manual so I may be very mistaken.