I really like it for certain things, but I did some profiling recently and there _is_ more overhead in calling a function than I'd really like (at least on the VM - the YYC and inline code should make it quite a bit nicer). It's more performant in some situations than other - but it can be nicer to write code for!
Just a note....calling a function in order to return a struct that you point-reference into in order to get a variable or run a function will eventually slow down your game. A better option would simply be to just create it as a global variable and use a macro to point to the global.....since anything in a script file that is outside of a function will be initialized once anyway. So something like: global.__time = { blah blah blah} #macro Time global.__time This way there is no calling any functionality or returning a struct, the macro replaces it in preprocessing so it's as if you wrote the entire thing out directly. This does make the autoupdate feature you added at the end of the video not available....but you could add it to the macro, if you REALLY want it to update, like this (just have 'Update' return 0): #macro Time global.__time.update()+global.__time So if you were to write: var a = Time.dt; It gets replaced with: var a = global.__time.update()+global.__time.dt; GMS runs the update function before it resolves the point reference to 'dt', so 'dt' will be updated by the time it gets the value. This way you only call 1 function, rather than 2.
If you call it constantly, yeah, although overhead from a function call itself isn't THAT much. If I need to use Time more than once or twice in a section of code I'll usually save it to a local variable at the top of the script. Random globals floating around usually get on my nerves after a while.
@@DragoniteSpam ...I was mainly just giving an alternative to using a function, that's all. I'm old school, so globals are part of my blood, having to instantiate objects just to hold variables for all other objects to look at "gets on MY nerves after a while"....lol. I think you call them singletons? Yeah, I don't like those.
cool trick! I was trying to do this recently... static class, like this.that. Thanks. Technically dt or whatev could also be functions ensuring its updated (or something specific to that memeber) before returning. then could you just put up some macro within get_static_time so you dont need () ?! code reviewers might scream because condescending nature but.... anything to not go global, hurts my eyes and private requirements...