Skip to content

scripting_4_variables

Camille Baillat edited this page Feb 17, 2022 · 1 revision

Variables and variable lists

Variables

Variables and variable lists are probably THE most used thing in script for more advanced modders. They serve as a form of storage on scopes. You can set them on:

  • {width="2.1041666666666665in" height="3.21875in"}characters

  • titles

  • faiths/religions

  • cultures

  • schemes

  • secrets

  • holy orders

  • dynasties

  • houses

  • armies

  • wars

  • etc.

We can save a few things with variables. One, we can save values (either flat numbers or script values.) If you save a number, you can use the command change_variable to edit the value at any time.

You can also save scoped objects with a variable. Think of it like save_scope_as, except the scope lasts beyond the chain of effects or events.

Finally, you can save flags with variables. Flags are essentially just strings of text (you cannot use spaces.) You won't really ever be able to use flags for any real purpose until you start GUI modding, so ignore this part for now.

To fetch the value of a variable in your code, you can use what is essentially a call scope of var:example_var. You can't call a variable saved on another scope, only those saved on the current scope. To remove a variable, we have the remove_variable = varname effect. We can also set_global_variable, change_global_variable, and remove_global_variable, which can be set anywhere and called anywhere with global_var:globalvarname.

Variable Lists

{width="2.281568241469816in" height="3.229617235345582in"}Variable lists are essentially a slightly more advanced form of variables. They can save multiple objects, and you can use them like you do a normal list (such as every_ruler.)

You can save the same things on them as you can on variables, except for numerical values. These are very useful for getting a group of characters, titles, or what have you that you want to apply something to en masse. They're also used in GUI a lot.

We can also use any_in_list, which is essentially the same as random_in_list but for triggers. The syntax here is kinda weird, but you get use to it. You cannot use the var:name to fetch the value here, since it can have multiply entries. Once again, we can also make a global version of a variable list, with add_to_global_variable_list, random_in_global_list, every_in_global_list, any_in_global_list, and remove_list_global_variable.

Clone this wiki locally