Variables are Skript's way to save data. Every variable has a name and a value, i.e. some stored data. You can put variables anywhere in your triggers to replace something, e.g. you can replace a location with a variable that holds a location.
This can for example be used for a /home command: make a variable ‘home’ and a command /home which teleports the player to the location stored in the ‘home’ variable.
To distinguish variables from the rest of the trigger their name has to be put in curly brackets like this: {variable name}. A variable's name can also contain expressions, e.g. to make a ‘home’ variable for every player you can make a variable like {home.%player%} where %player% will be replaced by the player's name every time the variable is used, which essentially creates a ‘home’ variable that is different for every player.
All variables are saved in a file called ‘variables.csv’ in the plugin's folder. Please do not edit the file manually, if you do something wrong you might wipe out some variables. The variables are written to this file constantly, so a server crash will make you loose at most one variable. Starting with version 2.0 you can also choose to save variables in a database which can also be monitored for changes, e.g. if you have multiple servers and want to synchronize variables between them.
There are 3 different kinds of variables: ‘normal’ variables, local variables and options. Normal variables (usually simply called variables) are unique, i.e. there can only exist one variable with the same name, and they are saved between server restarts.
Local variables (which are identified with an underscore: {_local variable} are ‘local to the event’, which means that there can exist several of these variables with the same name simultaneously, e.g. the following trigger will send a player his name one minute after he joined:
Code (Skript):
- on join:
- set {_player} to player
- wait a minute
- message "%{_player}%" #The local variable is unchanged no matter how many players joined in the meantime