Global Variables - Gr770/UnifiedUICK3 Wiki

Global Variable Setup for UNIUI

Global Startup Variables are required for UNIUI to detect when your mod is loaded.

Thankfully this is the easiest thing to add to your mod for compatibility. Let's go through it.

First you'll want to set up an on_action file in your common/on_action folder with a custom file name. Be sure to make it UTF-8 BOM.

Inside the on_actions you want to set up an on_action for game start

on_game_start = {
    on_actions = {
        on_<your_mod_name_here>_start
    }
}

Then from there you can place the set setup on_action right below it as follows.

on_game_start = {
    on_actions = {
        on_<your_mod_name_here>_start
    }
}
on_your_mod_name_here_start = {
    effect = {
        set_global_variable = {
	    name = <ModName>_is_loaded
	    value = yes
	}
    }
}

Perfect! Now all you'll need to do is let the UNIUI Team know what is your variable so they can prepare to integrate your mod.

Using Global Vars for UI

For using the global vars from other mods in your own unique gui files, you'll want to set up a scripted gui and or scripted triggers. In this example we'll be using sgui. Create a unique file under common/scripted_guis with UTF-8 BOM.

For simplicity we will want to call our sgui something like <mod>_is_loaded_sgui

StA_is_loaded_sgui = {
}

Global vars can be access true any scope type and you'll likely just want to call the sgui through the player so set the scope type to the character.

StA_is_loaded_sgui = {
    scope = character 
}

Now we mostly want to determine if the gui element can be shown so we want to use the trigger under is_shown

StA_is_loaded_sgui = {
    scope = character
    is_shown = {
        exists = global_var:mod_StA_active
    } 
}

The good news is you can use exists = global_var:<modname>_active to also determine if a button can be clicked and determine which effects will happen.

<my_mod_name>_sgui = {
    scope = character
    is_shown = {
        exists = global_var:<modname>_active
        other_triggers....
    }
    is_valid = {
        exists = global_var:<modname>_active
        other_triggers....
    }
    effect = {
         IF = {
             limit = {
                 exists = global_var:<modname>_active
                 other_triggers....
             }
             effects...
         }
         else = {
             effects...
         }
    }
}

Calling the sgui is pretty simple for our basic visibility sgui above we would use the below in most cases

GetScriptedGui('StA_is_loaded_sgui').IsShown(GuiScope.SetRoot(Character.MakeScope).End)

And of course the different sections can be accessed by replacing IsShown with the following:

is_shown > GetScriptedGui('<my_mod_name>_sgui').IsShown(GuiScope.SetRoot(Character.MakeScope).End)

is_valid > GetScriptedGui('<my_mod_name>_sgui').IsValid(GuiScope.SetRoot(Character.MakeScope).End)

effect > GetScriptedGui('<my_mod_name>_sgui').Execute(GuiScope.SetRoot(Character.MakeScope).End)

is_shown Tooltip > GetScriptedGui('<my_mod_name>_sgui').IsShownTooltip(GuiScope.SetRoot(Character.MakeScope).End)

is_valid Tooltip > GetScriptedGui('<my_mod_name>_sgui').IsValidTooltip(GuiScope.SetRoot(Character.MakeScope).End)

effect Tooltip > GetScriptedGui('<my_mod_name>_sgui').ExecuteTooltip(GuiScope.SetRoot(Character.MakeScope).End)

Current List of Global Vars

For those that want to integrate mods into your own, you can use preexisting global vars to detect when another mod is loaded to change your events and decisions script accordingly.

Kingdom of Heaven: KoH_is_loaded (uses Res Publica)

Core Title Inheritance: CTI_is_loaded

Submission to Authority: StA_is_loaded

Prisoners of War: PoW_is_loaded

Terms and Conditions May Apply: TCMA_is_loaded

In My Honest Opinion: IMHO_is_loaded

Community Name Packs: CNP_loaded

Custom Title Form of Address: CTFA_vanity_title_0

Biography: chronicle_mod_version

Inherichance: Inherichance_is_loaded

Special Requirements

Res Publica: play_house_heads and play_republic_leaders Use OR = {} to check these

Getting rid of startup errors

When creating a global variable that can be used in UniUI, but that you don't use in your mod yourself, when your mod is loaded without UniUI, it will throw this error on game start:

[16:15:21][jomini_effect.cpp:311]: Variable '<your_mod_name>_is_loaded' is set but is never used

To get rid of this error and clean up your error log, you can create an error suppression event: even vanilla does this!

Just make an event file with the following content:

namespace = <your_mod_name>_error_suppression

<your_mod_name>_error_suppression.0001 = {
  hidden = yes
  trigger = {
    exists = global_var:<your_mod_name>_is_loaded
  }
  effect = {
  }
}

With this, the game will consider the variable as being used, and will stop throwing that error everytime your mod is loaded without UniUI.