GMS 2 [SOLVED (somewhat] Safe way to test if variable is a ds_list

cidwel

Member
Hello

I was using a function I made called "length" that checks the kind of array, list or map you pass and returns the length of the structure, It seems it is failing in the ds_list/ds_map detectiop with the ds_exists function.

Right now seems that a ds_map can be also a ds_list using the function ds_exists() Still I'm not sure if this could be considered a bug, but it is really encouraging that it seems there's no true way to differentiate these kind of structures

Please, see the attached image.

The first structure in the picture is when you select in debugger to represent the variable called dsList as DS List
the second one is when you select it to reprensent the dsList as DS Map,

The best part is when it seems that dsLists can be represented as dsMaps and get random values from other objects in your game....

The dsList comes from a simple object: oScriptDialog
The dsMap that it seems is wrongly referencing is from another kind of object: oGame.mobClassDB

Does exist a possibility to determine the real type of structure that it is?
 

Attachments

jo-thijs

Member
Hello

I was using a function I made called "length" that checks the kind of array, list or map you pass and returns the length of the structure, It seems it is failing in the ds_list/ds_map detectiop with the ds_exists function.

Right now seems that a ds_map can be also a ds_list using the function ds_exists() Still I'm not sure if this could be considered a bug, but it is really encouraging that it seems there's no true way to differentiate these kind of structures

Please, see the attached image. The best part is when it seems that dsLists can be represented as dsMaps and get random values from other objects in your game....

The dsList comes from a simple object: oScriptDialog
The dsMap that it seems is wrongly referencing is from another kind of object: oGame.mobClassDB

Does exist a possibility to determine the real type of structure that it is?
Nope, there doesn't exist a way.

The variables only store a reference to the data structures.
Those references are numbers.
GameMaker assumes you as the programmer know which variables represent which data structures,
so it doesn't make distinct numbers for different data structures.
As a result, this is not a bug.

Why do you need this functionality anyway?

And why do you address @RichHopelessComposer in your screenshot?
 
In an upcoming update (unknown when though) data structures will become true datatypes instead of being referred to with just an index. That might perhaps also come with functionality to check/verify the type
 

cidwel

Member
In an upcoming update (unknown when though) data structures will become true datatypes instead of being referred to with just an index. That might perhaps also come with functionality to check/verify the type
oooooo!!! I'll be waiting then. Thanks!
 

BoB3k

Member
This is marked solved? A random forum poster saying this may be fixed in the future is not solved.
 

cidwel

Member
Maybe would be worth checking the new API of the new beta version of GM:S to see if we got a way to get the kind of structure

Maybe we finally got a way to solve this. I "solved" it removing my "length" function and testing lists/maps in a classic way. So the response this thread got was "no, there is not a way to know the kind of structure".
So the initial question was solved
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Right now seems that a ds_map can be also a ds_list using the function ds_exists() Still I'm not sure if this could be considered a bug, but it is really encouraging that it seems there's no true way to differentiate these kind of structures
Afaik, the ds_exists function should be ale to tell the difference between structures, even though they share the same internal ID value. So, yeah, please file a bug and supply a link to a test project if you can.

In an upcoming update (unknown when though) data structures will become true datatypes instead of being referred to with just an index. That might perhaps also come with functionality to check/verify the type
Just want to point out that the "upcoming update" may be several years down the line, as changing the way data structures are referenced is actually a very big task, requiring a lot of thought and preparation to ensure backwards compatibility. So, yeah, the devs really want to do this, and have said they will do it, but - to be clear - it's not in the "soon" timeframe at all...
 

FrostyCat

Member
Just want to point out that the "upcoming update" may be several years down the line, as changing the way data structures are referenced is actually a very big task, requiring a lot of thought and preparation to ensure backwards compatibility. So, yeah, the devs really want to do this, and have said they will do it, but - to be clear - it's not in the "soon" timeframe at all...
Then may I interest you in my latest project? I'll even let YoYo have the project if this means data structures in GML will stop sticking out like a sore thumb.
 

Nidoking

Member
Afaik, the ds_exists function should be ale to tell the difference between structures, even though they share the same internal ID value.
I'm taking it that the issue is that, say, if you have a variable my_list that is a list reference equal to 1, and you have another variable my_map that's a map reference equal to 1, then ds_exists(my_list, ds_type_map) will return true because there is a map with index 1, even though the variable my_list is used to reference a list. To me, given the flexibility of the program, it's the programmer's responsibility to keep the variables for different data types separate and to know what type of data structure a variable references, if it exists at all.
 

Yal

šŸ§ *penguin noises*
GMC Elder
YellowAfterlife (who is not me, just for the record) also has made an extension called Quality Data Structures which might be useful. It also has a bunch of error handling to catch the most common data structure wrangling mistakes.
 
Top