1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

how do i create a global variable?

Discussion in 'Modding Help' started by stolij, Jul 26, 2017.

  1. stolij

    stolij Catapult Fodder

    Messages:
    1
    i want to create a global bool, which i can set and read from multiple scripts, but i dont know how to do this. Does anyone know how to do this?
     
  2. makmoud98

    makmoud98 You are already DEAD Forum Moderator Staff Alumni Tester

    Messages:
    586
    you can make a separate script called Constants.as or whatever and put the constants in there. just put:
    Code:
    #include "Constants.as"
    at the top of the script you want to use them in

    if you are looking for something mutable, you will need to set the boolean differently. You can use CRules to store your boolean by doing
    Code:
    getRules().set_bool("some name", true);
    and get it by doing
    Code:
    getRules().get_bool("some name");
    you can also use CPlayer, CBlob, or CMap. obviously there is a time and a place for using each one. also you need to be careful with setting booleans on client and server; they need to be synced. use the sync function:
    Code:
    Sync(const string&in name, bool onlyServer)
    ex:
    Code:
    getRules().Sync("some name", true);
    you can see examples of the set/get functions being used throughout the game's code. as well as the sync function. good luck
     
    Last edited: Jul 26, 2017
    MillerTheRealRacoon and bunnie like this.