Tutorial 1: Manipulating PS for a stamina system
So far we've shown how PS can be written to, and read, but not how to manipulate any data. There are specific ways to do that! Let's say we want to to limit how many tiles a player can move before needing to rest for a certain amount of time. We can use PS to keep track of a player's stamina.
For this example we want to keep track of any player's stamina the moment they come in the Dream. We can do that by setting data for every player like so:
(0:9) When someone arrives in the Dream,
(5:600) memorize that the PhoenixSpeak info {Stamina} about the triggering player will now be 3. (set to max steps in between rest)
Since PS can't be manipulated directly, any data we want to change around has to first be grabbed and put into a string or variable, modified, and then stored again.
(0:1) Whenever someone moves, (This is the primary trigger for stamina depletion)
(1:5) and they successfully moved, (And they weren’t blocked, so they actually changed positions)
(5:610) remember the PhoenixSpeak info {Stamina} about the triggering player, and put it in variable %Stamina. (Here, we are grabbing the data from the Phoenixspeak, and putting it into a variable so we may manipulate it if need be)
First we check to see if they moved with 0 stamina, if they did, we move them back and tell them to take a break:
(0:1) Whenever someone moves, (Here we have the primary trigger again for stamina depletion)
(1:5) and they successfully moved, (Again, we’re making sure they didn’t bump into anyone)
(1:200) and variable %Stamina is equal to 0, (Here, we’re using a condition to check if they had no stamina. You can't use a condition after an area, filter, or effect. So we had to use a separate block of DS)
(5:18) move the triggering player back where they came from. (We move them to the previous square, because they have no stamina)
(5:200) emit message {You need to rest!} to the triggering player. (Then we tell them why they couldn’t move)
Next we check to see if they had enough stamina to move. One square = 1 stamina deducted. So we're making sure they have enough. If they do have enough stamina, we deduct one and set store the new value.
Note: we do this after checking for 0 stamina, because of the ordering of DS. If we had subtracted 1, making the stamina 0, then the move back block would be triggered in conjunction to the subtraction block.
(0:1) Whenever someone moves,
(1:5) and they successfully moved, (Changed squares?)
(1:201) and variable %Stamina is more than 0, (This is a condition to make sure they had some stamina, if this conditions passes, we won’t need to move them back)
(5:304) take variable %Stamina and subtract 1 from it. (Instead, we subtract one from their current stamina.)
(5:600) memorize that the PhoenixSpeak info {Stamina} about the triggering player will now be %Stamina. (Then we make sure to set their PhoenixSpeak info to it, so it's memorized. Variables are global, character PS isn’t)
Or they idle for 2 seconds:
(0:71) When someone stays in the same square for 2 seconds, (The amount of idle time it takes to restore stamina)
(5:600) memorize that the PhoenixSpeak info {Stamina} about the triggering player will now be 3. (set to max steps in between rest)
Share this:
-
-
-