GMS 2 REAL argument is undefined?

Discussion in 'Programming' started by BitRoarGames, Mar 29, 2019.

  1. BitRoarGames

    BitRoarGames Member

    Joined:
    Mar 18, 2019
    Posts:
    10
    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?
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,965
    What's the code related to the error?
     
  3. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,307
    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.
     
    Binsk likes this.
  4. BitRoarGames

    BitRoarGames Member

    Joined:
    Mar 18, 2019
    Posts:
    10
    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.
     
  5. BitRoarGames

    BitRoarGames Member

    Joined:
    Mar 18, 2019
    Posts:
    10

    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.
     
  6. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,307
    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"]));
    
     
  7. BitRoarGames

    BitRoarGames Member

    Joined:
    Mar 18, 2019
    Posts:
    10
    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!
     
  8. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,155
    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:

     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice