Conditions are the way to take decisions based on the current state of your game. They are built around boolean values. A boolean value is a value that is either true
or false
.
To make use of these, you have to know about the set_global
command we explained in the previous Global states and saving chapter
This command sets a global flag to a certain boolean value. For example:
set_global player_has_money true
To sum this up, we can say we will use set_global
to remember the player has done something we might need later. Now that you understand this, conditions are a natural consequence of the presence of boolean values in Escoria. Because if we need later to know if the user made a previous action to give him the possibility to do another, we’ll need to write a condition.
Conditions enable you to take different actions based on some global flags. Briefly we will be able to check the value of a global and give the user the right gaming options, corresponding to what has been stored in globals.
To execute an Esc command conditionally, all you need to do is to add a list of global flags at the end of your command, like so: [flag1, flag2, flag3]
. The command will run if all the flags of the list have a true value.
You can also negate a flag in the list by preceding it with a !
character, this will execute the command if the flag is false.
In this example, the first line happens only if the player_has_money is false or unset. The second line happens if the global has been set AND if parents_are_there is false (the comma means that both have to be true).
say shopkeeper "Go away you little brat!" [!player_has_money]
say shopkeeper "Hehehe, there you go, here’s your candy bar." [player_has_money, !parents_are_there]
Of course, the game may have many conditions depending of the complexity of the scenes and the problems to solve. And often, several things will happen if a global is set correctly to our wishes. In this case, we’ll need a block as defined in the previous Structure chapter.
One of the most useful features of conditions is that you can use them with blocks, effectively running the entire block based on the conditions list like so:
> [picked_item, !god_appeared]
say old_man "Good! Now offer it to our almighty panda god, I’ll summon them for you."
set_global god_appeared true
set_active bamboo_god true
These three commands (say, set_global, set_active) taken from our sample game will only run when introduced
and picked_item
are true, and god_appeared
is false. There are many other example of conditions in this little game. For example, the player can take the bamboos only if he has already spoken to the old man. Here, on talk verb, we open a block that will happen if the introduced global is not set. This is the global we will use to remember if the player did talk to the old man. In this case, the old man talks and sets the introduced globals to true, to that we can do another action (pick the bamboo) later or if we come back to the old man so that he can say something else.
In the old_man.esc we have:
:talk
> [!introduced]
say old_man "Hello young panda, today is time for your first offering to the almighty panda god!" default avatar_old_man
set_global introduced true
stop
Then the block if he already introduced
> [picked_item, !god_appeared]
say old_man "Now offer the bamboo to our almighty panda god, I’ll summon him for you." default avatar_old_man
set_global god_appeared true
set_active bamboo_god true
stop
Where we make the god appear. We have mixed the picked_item state with another global, because we want to answer only if the god panda wasn't summoned yet.
If the action matches no conditions, a fallback action can be provided.
Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.
Vous devriez rafraîchir la page.