• 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!

GameMaker REAL argument is undefined?

B

BitRoarGames

Guest
IDE: v2.2.2.413
Runtime: v2.2.2.326

Hey, I'm having an issue with the new Studio 2 update that just hit. I recently updated and out of the blue, I'm having an issue converting a saved string to a real variable using the "real" function. I've switched back to the previous 2.2.1.291 and the issue doesn't occur so it seems to be something conflicting with this new version. Here's the error:

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Other Event: Room Start
for object obj_draw_ctrl:
REAL argument is undefined
at gml_Script_scr_load_project_json (line 75) - dota[myi,2] = real(_map[? "a"+string(myi)+"c"]); //Color
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scr_load_project_json (line 75)
called from - gml_Object_obj_draw_ctrl_Other_4 (line 19) - scr_load_project_json();


Any ideas of what the problem could be and why this just suddently started happening right after the new update?
 

samspade

Member
IDE: v2.2.2.413
Runtime: v2.2.2.326

Hey, I'm having an issue with the new Studio 2 update that just hit. I recently updated and out of the blue, I'm having an issue converting a saved string to a real variable using the "real" function. I've switched back to the previous 2.2.1.291 and the issue doesn't occur so it seems to be something conflicting with this new version. Here's the error:

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Other Event: Room Start
for object obj_draw_ctrl:
REAL argument is undefined
at gml_Script_scr_load_project_json (line 75) - dota[myi,2] = real(_map[? "a"+string(myi)+"c"]); //Color
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scr_load_project_json (line 75)
called from - gml_Object_obj_draw_ctrl_Other_4 (line 19) - scr_load_project_json();


Any ideas of what the problem could be and why this just suddently started happening right after the new update?
What's the code related to the error?
 

FrostyCat

Redemption Seeker
This is happening after the 2.2.2 update because you're doing something wrong to start with.

At least one of dota, myi, or _map is actually undefined, you just didn't realize it. 2.2.1 and below tried forgiving your transgression by pretending it's 0, and while it silenced the error, it doesn't make the code right. 2.2.2 is now doing the right thing by calling you out.

Start by putting the following just before that line in the error:
Code:
show_debug_message("dota: " + typeof(dota));
show_debug_message("myi: " + typeof(myi));
show_debug_message("_map: " + typeof(_map));
If any of the types aren't what you expect, that's where you should begin your investigation.
 
B

BitRoarGames

Guest
What's the code related to the error?
How do you mean? What I'm doing is working with a pixel by pixel character creator where the colors are written and saved as strings to a text file however they are loaded back in as real variables. I've been using this method to save space in the character file since wring something as a real variable seems to add unnecessary decimal points and takes far more bytes of memory in the end while strings seems to write only what's necessary.
 
B

BitRoarGames

Guest
This is happening after the 2.2.2 update because you're doing something wrong to start with.

At least one of dota, myi, or _map is actually undefined, you just didn't realize it. 2.2.1 and below tried forgiving your transgression by pretending it's 0, and while it silenced the error, it doesn't make the code right. 2.2.2 is now doing the right thing by calling you out.

Start by putting the following just before that line in the error:
Code:
show_debug_message("dota: " + typeof(dota));
show_debug_message("myi: " + typeof(myi));
show_debug_message("_map: " + typeof(_map));
If any of the types aren't what you expect, that's where you should begin your investigation.

dota[myi,0] = _map[? "a"+string(myi)+"x"]; //X Position
dota[myi,1] = _map[? "a"+string(myi)+"y"]; //Y Position
dota[myi,2] = real(_map[? "a"+string(myi)+"c"]); //Color

issue doesn't occur for any of the lines just above the color loading so I can only assume that if it we're an undefined variable, it would have hit right at X Position and not two lines below it. "myi" is defined as var myi=0; just before any of this is loaded and "_map" is working fine while loading all before the characters variables and just like before, the issue doesn't occur until 2 lines down which would mean it's not causing an issue for both x and y position but only color.
 

FrostyCat

Redemption Seeker
dota[myi,0] = _map[? "a"+string(myi)+"x"]; //X Position
dota[myi,1] = _map[? "a"+string(myi)+"y"]; //Y Position
dota[myi,2] = real(_map[? "a"+string(myi)+"c"]); //Color

issue doesn't occur for any of the lines just above the color loading so I can only assume that if it we're an undefined variable, it would have hit right at X Position and not two lines below it. "myi" is defined as var myi=0; just before any of this is loaded and "_map" is working fine while loading all before the characters variables and just like before, the issue doesn't occur until 2 lines down which would mean it's not causing an issue for both x and y position but only color.
Then this would mean _map[? "a"+string(myi)+"c"] cannot be cast to a real. Use typeof() and show_debug_message() as I described in my previous post to find out what type it actually is and what's actually there.
Code:
show_debug_message("axc: " + typeof(_map[? "a"+string(myi)+"c"]) + " " + string(_map[? "a"+string(myi)+"c"]));
 
B

BitRoarGames

Guest
Then this would mean _map[? "a"+string(myi)+"c"] cannot be cast to a real. Use typeof() and show_debug_message() as I described in my previous post to find out what type it actually is and what's actually there.
Code:
show_debug_message("axc: " + typeof(_map[? "a"+string(myi)+"c"]) + " " + string(_map[? "a"+string(myi)+"c"]));
You were absolutely correct and the axc variable was undefined. I had forgotten that I made it so that if the color being saved was black or 0, it would simply omit it from the writing process to save space. This works well except for the fact that it left the color variable trying to read a ds map entry that didn't exist. Explains why it worked in the older version but not in the newer one.

My solution was to simply run a "ds_map_exists" function just before attempting to read the colors. Thank you very much for all the help brother!
 
Edit : Just saw you post after I posted this...doh!

I started getting same errors for attempting real() conversion on a number I had converted to a string using string_format(num, 3, 2).

In some cases, the string being returned had 1 or two spaces before the actual digits of the number.

In any case, just confirming what others have said above. You need to check carefully the string you are trying to convert to a real and make sure its valid, as GMS is now seems stricter on the number conversion process. Or at least, its now working as it is supposed to have worked in the first place.

From the manual:

This function can be used to turn a given string into a real number. When using this function, numbers, minus signs, decimal points and exponential parts in the string are taken into account, while other characters (such as letters) will cause an error to be thrown. If you know, or suspect, that a string may have other characters then you can use string_digits() to remove all non-numeric characters, before using this function to turn the resulting string into a real number.
 
Top