Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

GMLive and singleton - solution

A topic by gnysek created Feb 13, 2023 Views: 184
Viewing posts 1 to 1
(1 edit)

GM 2023.1 introduced singletons:

function foo() constructor {
  static bar = 1;
}

foo(); // initialised at least once so static is set

/// now you can do this anywhere:
foo.bar; // returns 1

However, GMLive (yet) doesn’t support this syntax. There’s however very easy way to bypass this issue. Instead of foo.bar you need to write static_get(foo).bar - as in fact while compiling, GM translates former to latter, which means only latter is used in compiled games.

Have fun playing with new syntax!