You are not logged in.
Pages: 1
Wrote this quite a while ago.
//ds_list_exists(index) returns whether the ds_list with given index exists or not
if !(is_real(argument0)) {return false;}
var ds_temp, ds_temp_list, i;
ds_temp_list = ds_list_create();
ds_temp = ds_temp_list;
argument0 = round(argument0);
while (ds_temp < argument0)
{
ds_temp = ds_list_create();
ds_list_add(ds_temp_list, ds_temp);
}
for (i = ds_list_size(ds_temp_list) - 1; i >= 0; i -= 1)
{
ds_list_destroy(ds_list_find_value(ds_temp_list, i));
}
ds_list_destroy(ds_temp_list);
return ds_temp != argument0;
Not sure if you will really want to use it though. It uses a bit of a trick that when creating a new list GM reuses ds_list indexes that have been destroyed.
Last edited by flexaplex (2010-06-17 14:52:52)
Offline
Not a bad approach, as long as the list being searched for doesn't have a huge id. Looks like this technique could be applied to any type of data structure.
There's one thing I think I'd change, namely the bit where you reject ids with a fractional component. The existing ds_list functions accept these for arguments, rounding to the nearest integer. I suggest "argument0 = round(argument0)" instead of your check.
It looks like it handles negative ids gracefully, but I haven't actually tested it yet. Does it?
Abusing forum power since 1986.
Offline
Not a bad approach, as long as the list being searched for doesn't have a huge id. Looks like this technique could be applied to any type of data structure.
There's one thing I think I'd change, namely the bit where you reject ids with a fractional component. The existing ds_list functions accept these for arguments, rounding to the nearest integer. I suggest "argument0 = round(argument0)" instead of your check.
It looks like it handles negative ids gracefully, but I haven't actually tested it yet. Does it?
Yes it can be expanded to other data structures. I think this should function be default built into GM as well with all the data structures.
It does handle negatives correctly. I agree changing to round() is better, I had not thought about that.
This is the only approach found that was able to handle things correctly.
Last edited by flexaplex (2010-06-17 14:54:30)
Offline
Pages: 1