D
DennisGMC
Guest
In my game i need to create a list holding 3 values the sprite id x and y coordinates. I have no idea how long the list is going to be so i can't limit it like a ds_grid. What would be the most efficient way to do this?
enum rv
{
posx=0,
posy=1,
sprite=2,
<otherthing>=3,
<anotherthing>=4
}
script random_pos
arrayreturn[rv.posx] = irandom(100)
arrayreturn[rv.posy] = irandom(100)
return arrayreturn
in code :
rand = random_pos() //rand is a pointer on arrayreturn of the random_pos script
obj.x = rand[rv.posx]
obj.y = rand[rv.posy]
item[0,1] = item0.sprite_index;
item[0,2] = item0.x;
item[0,3] = item0.y;
item[1,1] = item1.sprite_index;
item[1,2] = item1.x;
item[1,3] = item1.y;
FYI, the argument limit for scripts and functions was removed an update or two back. you can pass as many values ad you need to them now.You can resize grids FYI. I mention that because grids are very useful for a variety of things and its annoying but you can indeed resize them as needed.
For just insert and retrieve (without sorting or saving, etc.), I think I'd try a 2D array. If you need to do lookups or any other functions with it, I'd use a data structure.
When I do not need high performacne, I use ds_list, probably because I can add 15 values at a time, and can do lookups, etc. Trivial to save too (ds_list_write).