Hi, I'm still learning gsc scripting and I keep seeing the REGISTER_SYSTEM line around. I'm not completely new to coding but I can't figure out what this line actually doing. I was just hoping someone could shine some light on this one for me.
My only guess so far about what this is doing is that it's creating a singleton/ static instance of the class with the arguments being (string the same as the namespace, pointer to the constructor, ???).
system_name: Name of the system. To avoid confusion, this typically should match the namespace that the system is in.
preload_function: This function will automatically run during the pre initializion of a level load - this will be during the first frame, during the level load phase (before _load::main) for all code executes during the first frame is: autoexecs, level load, gametype, finalization
postload_function: This function will automatically run during the post initializion of a level load - this will be during the first frame, during the finalization phase for all code executes during the first frame is: autoexecs, level load, gametype, finalization
pre-reqs: Specifies a system or an array of systems that this system requires. This system will wait until the precahce and main functions return from the required systems before running this system's main function. Typically, this can be 'undefined'
system_name: Name of the system. To avoid confusion, this typically should match the namespace that the system is in.
preload_function: This function will automatically run during the pre initializion of a level load - this will be during the first frame, during the level load phase (before _load::main) for all code executes during the first frame is: autoexecs, level load, gametype, finalization
postload_function: This function will automatically run during the post initializion of a level load - this will be during the first frame, during the finalization phase for all code executes during the first frame is: autoexecs, level load, gametype, finalization
pre-reqs: Specifies a system or an array of systems that this system requires. This system will wait until the precahce and main functions return from the required systems before running this system's main function. Typically, this can be 'undefined'
In order to use it, you need to have this line at the top of your gsc file.
Code Snippet
Plaintext
#insert scripts\shared\shared.gsh;
Hope this helped.
Interesting, so in other words #namespace is only effective when used in conjuction with the register_system function. If I understand this correctly, using this method eliminates the need to manually add your init() and main() functions in your mapname.gsc as the usual process, when calling your custom scripts. Setting up your script this way will automatically call your init and main functions pre and post-load respectively. Do I have that right?
From what I can gather, yeah, it just makes it call itself, which is cool. The only other thing I'm curious about is if you can later call a system by name using this, but it sounds like you would just be calling the namespace which would accomplish the same thing. Cool though. Thanks for finding this, this makes a couple things makes more sense. Sorry for late response btw, life got busy and I forgot about this for a bit.