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

Discussion Should "Hello world" == pointer_null?

Discussion in 'GameMaker Studio 2 Community Tech Support' started by James Newnorth, Aug 1, 2019.

  1. James Newnorth

    James Newnorth Member

    Joined:
    Jul 10, 2018
    Posts:
    9
    Currently any string comparison with pointer_null is evaluated as true, is this as intended? In such case, why?
     
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,443
    Is it? I tried doing
    Code:
    var s = "Hello world";
    show_debug_message(pointer_null == s);
    in a new project on runtime 2.2.3.341 and it prints 0 as you'd expect
     
  3. James Newnorth

    James Newnorth Member

    Joined:
    Jul 10, 2018
    Posts:
    9
  4. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,443
  5. James Newnorth

    James Newnorth Member

    Joined:
    Jul 10, 2018
    Posts:
    9
  6. Homunculus

    Homunculus Member

    Joined:
    Jun 20, 2016
    Posts:
    817
    You could use typeof before the actual comparison. I'm not really up do date with the recent "consistency" changes, but checking the type before comparing seems like a good idea under any circumstances if you can't avoid the problem to begin with.
     
  7. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,443
    Can certainly try filing a suggestion for that.
     
  8. Hyomoto

    Hyomoto Member

    Joined:
    Jul 7, 2016
    Posts:
    1,078
    I can't comment on the `===` debate because, who knows? We know GML, at least for now, will never be a strictly typed language, and that's been the justification in the past. I can, however, comment on implementation. You are clearly using a dirty bit to redraw this element, but I'm wondering why your function doesn't simply read:
    Code:
    with ( argument0 ) {
        var_text = argument1;
        var_redraw = true;
    
    }
    The 'if' seems extraneous, at least in this particular function. You are asking for the GUI element to be updated. You may have a better reason than my simplistic vision, but let's say the player has five lives, falls into a pit, and a life needs to be subtracted. You call this function to update the lives display. Is it really relevant to this script to check if the new number is the same as the old number? The character fell into a pit, and the likelihood of the two numbers matching is low. Even so, the number of calls would be so infrequent as to make this problem moot. So, the other option is you are continuously calling this script to update the GUI unnecessarily, in which case it seems like the whole point of that particular comparison is to avoid a problem that exists somewhere else. The question at that point becomes, "If the script is being called unnecessarily, is the 'if' comparison cheaper than just flagging the HUD to be redrawn?" Depending on complexity, perhaps so, but if the purpose of dirty bit is optimization, that check raises a concern that this function is being used improperly to begin with. The whole purpose of flagging an element for updating is to prevent it from being done constantly. As written, you essentially have two sanity checks: "if the two values do not match" and, "if the flag is set". If that's true, it may be a case of do you trust yourself to call this function when the element actually needs to be updated? You can probably get rid of one of those checks, and thus the problem in question altogether, by answering yes.
     

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