How to save global variables with UPL.
Edit me

Settables & Switches

Settables and switches are the way to save your global data in your save file. They are defined in the Enums tab (F5) in Ldtk.

settables
switches

Defining Settables&Switches

When you go to the Enums tab in Ldtk and click on Settables or switches, you probably will not see any defined as of yet. You can freely add them by clicking “ADD VALUE”. (Green rectangle) IMPORTANT: When you add a Settable or Switch, Ldtk will automatically capitalise them. But in UPL you MUST refer to them in all lower-case characters. (see examples below)

Settables

Settables are variables that you can store anything in. In the example above, we have defined a story_chapter settable, which we can now access in UPL. It is an attribute of the set object (see Users & Objects). This means we can now access it to see how far the player has progressed or set it in UPL when the player progresses through the game!

set: story_chapter = 3
if(story_chapter > 2){
	exit
}

It can also contain other types of variables like names, percentages and whatever else could be useful saving. Keep in mind that you need to define them in the Ldtk Enums tab first!

set: rival_name = Prompt("What is the name of your rival?")

Switches

Switches are similar to settables, but they can only be on or off, or rather: True or False. They can be very useful when checking whether a certain character has been talked to, a puzzle has been completed or similar events. Technically you could use settables for anything you do with switches, but sometimes settables might be more difficult to keep track of. Switches have the advantage that they are ONLY True or False. This also means that we can do a little shorthand writing in our conditional actions (see conditional actions):

if(switch.obtained_coat){
	exit
}
# Make the player get the coat

Notice that we do not use ‘==’ to compare its value to True. Because it is either True or False we can simply leave out the part where we compare it to these values.