1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

convert to string error

Discussion in 'Programming' started by RizbIT, Dec 2, 2019.

  1. RizbIT

    RizbIT Member

    Joined:
    Jun 24, 2016
    Posts:
    471
    After converting from GMS 1 to GMS 2 i get some errors during runtime that i id not get with GMS1 after compiling.

    in GMS 2 i think when you ask it to do real(variable) where the variable is "" or maybe has no digits it gives an error
    unable to convert string "" to number.

    ive fixed one of these errors by using if string_digits(variable)!=""

    but there several more so is there a way to bypass or ignore these errors? as if the variable is "" then i want real(variable) to just return 0
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,699
    GMS 2 stopped ignoring digit conversion errors in 2.2.3.

    If the empty string is the only one causing you problems, just create a script called real_safe checking for that:
    Code:
    return (argument0 == "") ? 0 : real(argument0);
    
    Then do a global search-and-replace for real( with real_safe(.
     
    RizbIT likes this.
  3. RizbIT

    RizbIT Member

    Joined:
    Jun 24, 2016
    Posts:
    471
    That is a fantastic reply, thanks it will work great


    ** EDIT **
    Your solution works but only seems to work when using the Vm compilor, when using the YYC compilor i still get the same error which is strange.

    but then i dound it happened after calling instance_activate_all(), in YCC maybe due to some bug or delay any code ive put directly after calling instance_activate_all() doesnt get execured.
     
    Last edited: Dec 3, 2019

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