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

GML problem with instance variable

Discussion in 'Programming' started by Mickachu, Jun 26, 2019.

  1. Mickachu

    Mickachu Member

    Joined:
    Jun 26, 2019
    Posts:
    3
    Hi, i am kinda new to GMS2 and i need some help. I would like to create an instance variable called "hello" but GameMaker do not recognize it as an instance variable (in green) like "score". I would like to understand why it is doing this and how to fix it. By waiting, I wish you a nice day ;)
     

    Attached Files:

    • www.PNG
      www.PNG
      File size:
      4.7 KB
      Views:
      9
  2. Homunculus

    Homunculus Member

    Joined:
    Jun 20, 2016
    Posts:
    817
    That is correct. Instance variables are highlighted in blue.

    score is a built in variable, which is highlighted in green. Note that both built in instance and global variables are green (score being global in this case)
     
  3. Mickachu

    Mickachu Member

    Joined:
    Jun 26, 2019
    Posts:
    3
    Oh so I need to put global. in front of it. Thanks a lot and sorry for the disturbance, maybe if I searched a bit more I would have found the solution by myself. Have a great day!
     
  4. Homunculus

    Homunculus Member

    Joined:
    Jun 20, 2016
    Posts:
    817
    No you don't, your code is just fine. What I meant to say is that built in variables have a different color than user defined variables. Global AND instance variables that are built in are green, and for the global ones you don't need the "global" prefix.

    Also note that "score" (along with "health" and "lives") are deprecated global built in variables, meaning that while they work as intended, you should avoid using them.
     
  5. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,767
    No, that's not at all what was said.

    score is a built-in variable, this is why it is colored differently. It has nothing to do with it being a global or not and nobody suggested you to make it global.

    If you want instance variables to be green, you can change their color in the settings. Don't make them global just for that. It's fine the way you're doing it in the opening post.
     
  6. Mickachu

    Mickachu Member

    Joined:
    Jun 26, 2019
    Posts:
    3
    Ok, thanks a lot!
     

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