GML var question

Discussion in 'Programming' started by mizzy, Feb 4, 2019.

  1. mizzy

    mizzy Member

    Joined:
    Jan 14, 2019
    Posts:
    12
    Hello Happy Game Makers,

    I have a very noob question for you (was unable to find on my own):

    When I declare a variable.. do I have to write var before it?
    ex:
    var thingy = 0;
    or can i just write:
    thingy = 0;

    as far as I can tell they do the same thing, but I am very early on in my project (GMS2) and I don't want to shoot myself in the foot if it can be helped :)
    thanks!
     
  2. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,212
    No var means the variable is temporary scope and only stays valid for the currently executing event/script/statement. If you type var before a variable in the Create Event, that variable will not be valid in the Step Event, for instance. There's a big difference between the two. Look up variables and scope to read more about it.
     
  3. mizzy

    mizzy Member

    Joined:
    Jan 14, 2019
    Posts:
    12
    awesome! Will do, thanks!
     
  4. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,017

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