GMS 2.3+ Refactoring/Converting Code from 2.2.5 to 2.3


Hello guys, atm I refactor my whole game and i want to use the new 2.3 features.

Right now my code looks like this:

I have an object (singleton) which handles e.g. water (delete, spawn, draw water...)
additional I have scripts (<2.3), which are either
  • private __SINGLETONNAME_NAMEOFFUNC (__logic_water_draw) or
  • public SINGLETONNAME_NAMEOFFUNC (logic_water_removeAll)

I want to make it cleaner, since even the private funcs are global. I read, that i could use methods that are bound to the object like:


water_draw = function () {...}
This would help to decrease the global func amount.

Is this the way to go, or are there even better ways? My main goal is to encapsulate everthing to make future updates easier.

I am also open for additional tips, that I can use for my 2.2.5 to 2.3 refactoring.

I dont want to start with refactoring in 2 month again, because i notice there is a better way, therefore i ask. Thanks guys.



You don't really have private functions, even in 2.3, as even functions stored in method variables can still be accessed by anyone the way you would a normal variable (e.g. with statement or . notation). But if you have an object, especially if there is only one of those objects ever, then I would make functions that that object and only that object uses be methods declared in the object's create event. If there are a collection of scripts that other instances of other objects would want to access, I would put all of those into a single script asset.