UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

What does REGISTER_SYSTEM do?

broken avatar :(
Created 7 years ago
by Beceris
0 Members and 1 Guest are viewing this topic.
2,092 views
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 27 January 2017
Last active: 4 years ago
Posts
3
Respect
Forum Rank
Fresh Corpse
Primary Group
Member
×
Beceris's Groups
Beceris's Contact & Social Links
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.

Example Use from _zm_perk_staminup.gsc:

Code Snippet
Plaintext
REGISTER_SYSTEM( "zm_perk_staminup", &__init__, undefined )

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, ???).
Marked as best answer by Beceris 7 years ago
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 22 February 2013
Last active: 6 years ago
Posts
186
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Community Scripter
My Groups
More
Personal Quote
Every map needs a Panzer Soldat
Signature
HexPieRadiBirds Magical Fun Time Water Hole
×
AwesomePieMan's Groups
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
AwesomePieMan's Contact & Social Links
I looked through the code for documentation, here is what I found (In scripts/shared system_shared.gsc)

Code Snippet
Plaintext
/*///////////////////////////////////////////////////////////////////////////////////////////////////////////

Usage:

REGISTER_SYSTEM( <system_name>, <preload_function>, <postload_function>, <pre-reqs> )

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'

Example:

namespace coolsystem;

REGISTER_SYSTEM( "coolsystem", &__init__, undefined )

function __init__()
{
// Runs durring first frame, before any waits. 
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////*/

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.
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
Signature
Let he who has not sinned cast the first stone.
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
I looked through the code for documentation, here is what I found (In scripts/shared system_shared.gsc)

Code Snippet
Plaintext
/*///////////////////////////////////////////////////////////////////////////////////////////////////////////

Usage:

REGISTER_SYSTEM( <system_name>, <preload_function>, <postload_function>, <pre-reqs> )

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'

Example:

namespace coolsystem;

REGISTER_SYSTEM( "coolsystem", &__init__, undefined )

function __init__()
{
// Runs durring first frame, before any waits. 
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////*/

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?
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 27 January 2017
Last active: 4 years ago
Posts
3
Respect
Forum Rank
Fresh Corpse
Primary Group
Member
×
Beceris's Groups
Beceris's Contact & Social Links
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.

 
Loading ...