Singleton Pattern In Verse
51,226 Views
-
#define the global class global := class<varies><concrete>(): var MaybeMainDevice : ?main_device = false #create the global instance Global : global = global{} #function that makes it easier to access the device without checking if the option has a value GetMainDevice():main_device = if(MainDevice := Global.MaybeMainDevice?) then MainDevice else main_device{} #in your device's OnBegin you need this line: set Global.MaybeMainDevice = option{Self} #when you want to use it, you call: GetMainDevice()#define the global class global := class<varies><concrete>(): var MaybeMainDevice : ?main_device = false #create the global instance Global : global = global{} #function that makes it easier to access the device without checking if the option has a value GetMainDevice():main_device = if(MainDevice := Global.MaybeMainDevice?) then MainDevice else main_device{} #in your device's OnBegin you need this line: set Global.MaybeMainDevice = option{Self} #when you want to use it, you call: GetMainDevice()
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.