• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

 (Suggestion) Allow ds_list_insert to actually insert values in empty list

S

Shadowblitz16

Guest
can the yoyo game devs make ds_list_insetrt and other functions like it allow inserting values in indexes larger then the list size?

for example if you have a empty list
and you try to insert a value in index 2 it should insert it at index 2 and auto fill the the empty values before it with undefined.

right now it just ignores the function in this case and doesn't do anything
 

zbox

Member
GMC Elder
list[| x] = y

ds_list_set is an undocumented function which I assume works similarly.

Using either of these will (to the best of my memory) fill the preceding elements with 0.
 
S

Shadowblitz16

Guest
ds_list_set is not a function it does not highlight at all and I assume doesn't compile
also insert is to insert things aet would be to set things not vise versa
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
ds_list_set is not a function it does not highlight at all and I assume doesn't compile
also insert is to insert things aet would be to set things not vise versa
What you want is to start with a empty list and add something to the [n] position if so:
you can do:

Code:
list[| position] = value;
or, if you think is more appealing, create a function "ds_list_insert_adv" like this

Code:
///ds_list_insert_adv(list,position,value)

var list = argument0;
var position = argument1;
var value = argument2;
var list_size = ds_list_size(list)
if (position > list_size {
      for (var i = list_size; i < position; i++) {
            list[| i] = undefined;
      }
}
list[| position] = value;
EDIT:: updated to make function initialise new entries as undefined
 
Last edited:
S

Shadowblitz16

Guest
ok I did the first one but it's creating ds_maps in between index 2 and index 20 when they should be undefined.
is this a bug?
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
ok I did the first one but it's creating ds_maps in between index 2 and index 20 when they should be undefined.
is this a bug?
ahhH?!

a = ds_list_create();

a[| 5] = 10;

does this create a ds_map in position 0, 1, 2, 3, 4? this is just strange!

EDIT::
just tested... and it works fine... but doesn't make the undefined... only... gives then the value 0... I'll update the function..
 
Last edited:

GMWolf

aka fel666
ok I did the first one but it's creating ds_maps in between index 2 and index 20 when they should be undefined.
is this a bug?
Remember that when creating a map, you are returned an Index. That is just a number.
So if it fills it with a bunch of 0s, and you have created a map with index 0, then it will seem like its filled with the map if you check for that.
 
S

Shadowblitz16

Guest
@Fel666 I don't set the list index 2-19 to anything though.
I simply set list index 0 and 1 to a map containing variables for my tab, and I set list index 20-240 to the map containing my tile objects.
2-19 should be undefined because they are only filled with undefined values.

@xDGameStudios well it lets me set 0 to a ds_map in the debugger so that's why I thought it was a map
@Nocturne could you disable setting a value to a ds_map in the debugger when its not a ds_map? its causes confusion
maybe make empty ds_list values undefined since that's what they actually are?
 

GMWolf

aka fel666
@Fel666 I don't set the list index 2-19 to anything though.
I simply set list index 0 and 1 to a map containing variables for my tab, and I set list index 20-240 to the map containing my tile objects.
2-19 should be undefined because they are only filled with undefined values.

@xDGameStudios well it lets me set 0 to a ds_map in the debugger so that's why I thought it was a map
@Nocturne could you disable setting a value to a ds_map in the debugger when its not a ds_map? its causes confusion
maybe make empty ds_list values undefined since that's what they actually are?
Eh... should it really be undefined? Probably...
But GM's typing is such a mess... I just dont know.
 
S

Shadowblitz16

Guest
it should since I'm not setting it to anything and its just empty space allocated in the list

think of it this way what is an empty list? undefined.
what would be list entries that you haven't set? undefined.

it would basicly be empty space in the list but would only show in the debugger because you have a value at a higher index

it could just be that the debugger doesn't show list elements that have no value.
but then again how would you tell that they were empty if they aren't undefined?
 
Last edited by a moderator:

xDGameStudios

GameMaker Staff
GameMaker Dev.
it should since I'm not setting it to anything and its just empty space allocated in the list

think of it this way what is an empty list? undefined.
what would be list entries that you haven't set? undefined.

it would basicly be empty space in the list but would only show in the debugger because you have a value at a higher index

it could just be that the debugger doesn't show list elements that have no value.
but then again how would you tell that they were empty if they aren't undefined?
well in GML "undefined" isn't a type per-si it corresponds to the real number -4 ...so it really is a confusion xD
and as far as I know another thing I think is not very good is that:

negative numbers are considered to be "false":

if (5) : true
if (0) : false
if (-1) : false

that was something I got to get used to... because it really is not so standard.
this probably happens so that "undefined" gets considered as "false"

if (undefined) : false
(it's the same as if (-4) )
 
S

Shadowblitz16

Guest
undefined or -4 is an undefined list though.
so since this is a list, its elements should be undefined by default and set to values later.

for example I might have a list with a size of zero
- undefined

or a list with the size of one
- [0] undefined

or a list with the size of two with a value at the end
- [0] undefined
- [1] 0

what I'm trying to get across is that lists cannot hold index's higher than a undefined entry.
this makes it vary hard to have reserved elements that are not used

I would use a array but they are static and cannot be changed and I need that feature.

basically I'm trying to create an element system that uses a ds_list for a list of element instances (not object instances)
however the elements work off of these indices to figure out what element is selected and I need a way to have undefined elements in between
 

zbox

Member
GMC Elder
First of all - whatever you are trying to do here is going to be very achievable (your wording is not helping with my understanding of the conceptual problem though)

Either you are taking the wrong approach in implementing it or you already have your answer?
 

Juju

Member
well it lets me set 0 to a ds_map in the debugger so that's why I thought it was a map
That's a quirk of how GM's data structures work. They are given numeric indices. You can have both a ds_map and a ds_list with an index of 0 and they can hold different data.

well in GML "undefined" isn't a type per-si it corresponds to the real number -4 ...so it really is a confusion xD
Absolutely 100% inaccurate. undefined is a specific datatype that is return by some functions, noone is a numeric constant (equal to -4) that is returned by other functions. They are not the same.

I would use a array but they are static and cannot be changed and I need that feature.
Arrays in GML, unlike in other languages, can be dynamically resized.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
Absolutely 100% inaccurate. undefined is a specific datatype that is return by some functions, noone is a numeric constant (equal to -4) that is returned by other functions. They are not the same.
I'm sorry for my inaccurate answer.. I got myself confused... with "noone" :/
Thank you for the correction @Juju :)
 
can the yoyo game devs make ds_list_insetrt and other functions like it allow inserting values in indexes larger then the list size?

for example if you have a empty list
and you try to insert a value in index 2 it should insert it at index 2 and auto fill the the empty values before it with undefined.

right now it just ignores the function in this case and doesn't do anything
Probably easier using ds_maps in this case, and checking if the key exists.

ds_map_exists(id, key);
 
S

Shadowblitz16

Guest
I don't need a key. I need a numeric index.
the key would be completely worthless and I don't want to have to iterate over a ds_map all the time when doing it with a list is easier.

I don't see why everybody doesn't see this as a problem as a list element should be undefined unless it has a value.
and it certainly should NOT be a value that can be represented as a list or map.

here is an example since I am not very good at getting my point across..
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
they are only represented as a ds_list or ds_map if you set the debugger to read it as a ds_map or ds_list...
But yeah... all instances, data structures, arrays and.... should be given specific index ids..

for example:

8xxxxxxxx - for instances
7xxxxxxxx - for ds_grids
6xxxxxxxx - for ds_queue
5xxxxxxxx - for ds_priority
4xxxxxxxx - for ds_stack
3xxxxxxxx - for ds_list
2xxxxxxxx - for ds_map
1xxxxxxxx - for arrays

this way the debugger would instantly know which data type to read,
unless you store the number: 800000001 in and array...
and the debugger would think the number is a instance (which could not be)

Don't think GameMaker is build with that in mind... there are only two types of vars STRING and REAL
so if you have 1 ds_list, 1 ds_map and 1 ds_grid...

they are all given the index 0...

Code:
var map = ds_map_create();
var list = ds_list_create();
var grid = ds_grid_create(3,3);

a[| 2] = 10;
now if you write:

Code:
ds_list_find_value(map, 2);   // will print 10
ds_list_find_value(grid, 2);    // will print 10
ds_list_find_value(list, 2);     // will print 10
ds_list_find_value(0, 2);     // will print 10
it will work the same as reading the list!
So... making it undefined would not solve your problem.
because you can still get it confused...
but you can make then undefined using the function I gave in the previous post


EDIT::

Going even further:

Code:
a = ds_list_create();     // reference will be 0
b = ds_list_create();     // reference will be 1

a[| 0] = 1;
b[| 0] = 10;
now:

Code:
var c = ds_list_find_value(a[|0], 0);   // now c is 10!!!! because you just accessed list "b"
 
Last edited:

GMWolf

aka fel666
I don't need a key. I need a numeric index.
the key would be completely worthless and I don't want to have to iterate over a ds_map all the time when doing it with a list is easier.

I don't see why everybody doesn't see this as a problem as a list element should be undefined unless it has a value.
and it certainly should NOT be a value that can be represented as a list or map.

here is an example since I am not very good at getting my point across..
That is an issue you get in many programming languages. When creating a list of numbers, it will either be filled with 0s or with garbage.
Though in 00 language, you may get it filled with NULL if it was a list of objects.

The solution is to either fill the list with undefined yourself, or to use something like virtual initialization to keep track of what values you set, and did not set.

I think having them be undefined would be nice, in the rare case where you may set a value out of range, and then iterate over it.

My only question to you is, are you sure a list is the best tool for the job? Seems like a map is what you are actually looking for. Generally you don't want big gaps of garbage data in a list...
Perhaps not even a map, but a custom data structure?
Looking at your code a list really doesn't seem like the appropriate data structure.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
how to loop though every entry of a map the easy way!? I realised you want to use indexes (NUMBERS) so... use them

map = ds_map_create();
map[? 0] = "some object";
map[? 1] = "some other object";
map[? 10] = "another one";

to add entries to the map use

Code:
///ds_map_add_adv(map, index, value)

var map = argument0;
var index = argument1;
var value = argument2;

index = real(index); // if you know you are only adding index as number... you don't need this... this is just for safe...

map[? index] = value;

if (!ds_map_exists(map,"size")) {
    map[? "size"] = 1;
}
else {
    map[? "size"] = max(map[? "size"], index + 1);
}

Then to loop through it:
Code:
for (i = 0; i < map[? "size"]; i++) {
      data = map[? i];
      // it will return undefined if doesn't exist
}
don't use STRING "1", "2", "3", "4" .... use NUMBER 1, 2, 3, 4...
 

rwkay

GameMaker Staff
GameMaker Dev.
Well unfortunately this is not going to change as our hands have been tied by history on what happens with ds_list entries and due to the heavy hand of backwards compatibility that we are charged with maintaining means that even though I agree with you it is not something that is going to happen in the near future with ds_list entries, anything that has not been explicitly initialised will be set to zero.

Russell
 

GMWolf

aka fel666
Well unfortunately this is not going to change as our hands have been tied by history on what happens with ds_list entries and due to the heavy hand of backwards compatibility that we are charged with maintaining means that even though I agree with you it is not something that is going to happen in the near future with ds_list entries, anything that has not been explicitly initialised will be set to zero.

Russell
Its a shame. when GMS2 was announced it looked like YYG was trying to learn from their previous mistakes.
Its a shame that even though you are aware of them, you wont change them.
I for one would much rather like a better product even if it means i need to refactor poorly written code when upgrading to GMS2
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
Well unfortunately this is not going to change as our hands have been tied by history on what happens with ds_list entries and due to the heavy hand of backwards compatibility that we are charged with maintaining means that even though I agree with you it is not something that is going to happen in the near future with ds_list entries, anything that has not been explicitly initialised will be set to zero.

Russell
What about creating something like:

ds_set_default(value);
ds_list_set_default(value);

much like:

ds_set_precision();

that would let select the default not explicitly initialised variables, and would still maintain compatibility...
 

GMWolf

aka fel666
Yes they do... arrays are referenced... as numbers

Code:
a = [4,5,6,7];
map[? a] = 10;
even instances:

Code:
instance = instance_create(...)
map[? instance] = ["extra data here"]
Arrays are not indexed with numbers the way data structures are. They are their own data type.

Instance Ids are numbers, however.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
Arrays are not indexed with numbers the way data structures are. They are their own data type.

Instance Ids are numbers, however.
my bad you CAN use arrays... just checked!!
thank you for the correction! :)

I thought they were numbers too because they are index as hexadecimal numbers (in the debugger) so I thought they could somehow be converted
 
Last edited:
S

Shadowblitz16

Guest
so wait how does using instance work?
I know instances are reals but using them to index a ds_map? that doesn't seem useful.
 
@xDGameStudios what!? you can access maps with numeric indexes?
that would be so much more helpful thankyou!
Which is why I recommended it earlier... a key is a key is a key. 1 can be a key. 2 can be a key. 100 can be a key.

To check if the position 10 is undefined, you would just do:

ds_map_exists(whatever_your_maps_name_is, 10); // 'undefined' if false

Tada! Define the "keys" or "indexes" that you want, and all the rest in-between are 'undefined'.

You can also cycle existing values by using ds_map_find_first(id); ds_map_find_next(id); etc.
 
Top