• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM ds_exists argument 1 incorrect type (undefined) expecting a Number (YYGI32)

P

Prometheus1998_

Guest
I'm getting a strange error when using "ds_exists(ind,type)".
https://docs.yoyogames.com/source/dadiospice/002_reference/data structures/ds_exists.html

Here's the snippet of code:
dsid is the id of the data structure, passed into the script via argument.
Code:
if ds_exists(dsid, ds_type_map){
    return 0;
}

Here's the error message I'm getting, in full:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Other Event: Room End
for object obj_control:

ds_exists argument 1 incorrect type (undefined) expecting a Number (YYGI32)
at gml_Script_ds_check_type (line 7) - if ds_exists(dsid, ds_type_map){
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_ds_check_type (line 7)
called from - gml_Script_global_ds_clear (line 14) - type = ds_check_type(dsid);
called from - gml_Object_obj_control_EndRoomEvent_1 (line 1) - global_ds_clear(true);

The "type" argument is typed in exactly as the documentation page states it should, and the code editor has it colored in red, as it does all constants. What am I missing here, and how do I fix it?
 

chamaeleon

Member
ds_exists argument 1 incorrect type (undefined) expecting a Number (YYGI32)
Option A: Don't pass a variable to your script that you have not initialized with a value (say, from a data structure create function)
Option B:
Code:
if (!is_undefined(dsid)) {
  if (ds_exists(dsid, ds_type_map)) {
     return 0;
  }
}
 
Yes, what Chameleon said is right. Additionally, if you look closely at "ds_exists argument 1 incorrect type (undefined) expecting a Number (YYGI32)" it says argument 1 not argument 2, meaning the error sits with dsid, not the constant in the second argument slot.
 
P

Prometheus1998_

Guest
Don't all game maker (and most software, if I'm not mistaken) counters start at 0?
I know for a fact that, when writing scripts for Game Maker: Studio, either 1 or 2, the first variable assigned to an argument slot is labeled "argument0" or "argument[0]".

EDIT: Just to verify, I tried Chameleon's modification and it did... nothing. Still getting the exact same error.
 
No, not all Game Maker counters start at 0. The argument counter when an error is returned starts at 1. String manipulation also starts at 1. The problem is with dsid. My guess is would be that you either deleted the DS already, or have set dsid to point somewhere else at some point. We'd need more code to be able to tell exactly what is going on.
 

chamaeleon

Member
Don't all game maker (and most software, if I'm not mistaken) counters start at 0?
I know for a fact that, when writing scripts for Game Maker: Studio, either 1 or 2, the first variable assigned to an argument slot is labeled "argument0" or "argument[0]".
The argument count starts at 0 in your code but for some, perhaps historical reason, the error messages starts at 1 (as in, the "first", "second", etc., argument).

Just to verify, I tried Chameleon's modification and it did... nothing. Still getting the exact same error.
Code:
var foo = undefined;

if (!is_undefined(foo))
{
    if (ds_exists(foo, ds_type_map))
        show_debug_message("yes");
    else
        show_debug_message("no");
}
else
    show_debug_message("not defined");
Results in "not defined" as output in the debug console.
Code:
var foo = undefined;

if (ds_exists(foo, ds_type_map))
    show_debug_message("yes");
else
    show_debug_message("no");
Results in
Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object obj_generic:

ds_exists argument 1 incorrect type (undefined) expecting a Number (YYGI32)
 at gml_Object_obj_generic_Create_0 (line 6) - if (ds_exists(foo, ds_type_map))
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_generic_Create_0 (line 6)
If I do not assign anything at all to foo when I declare it, is_undefined() crashes the program with a message saying the variable has not been set before reading it.
 
Top