Basicaly, @Samuel_H_Young has made a custom checkpoint system for Trial of the Demon Hunter so the players who die don’t have to start the beta from the beginning. I have discovered a bug in it. It does not recover the inventory items or other stats you have used between the checkpoint and the point of death.
Anyways, I figured out how to solve it and offered to make an example. It was supposed to explain things to Samuel, but I decided to open a new thread because it, at least to me, seems useful for beta games. Here it is. I apologise if it is longer than it should be (it is) and if the comments are too confusing because I am generaly bad at explaining things.
This is the first time I post code. I am sorry if it ends up looking funny.
*title Checkpoint System
*scene_list
startup
*create health 10
*create weapon_a 3
*create weapon_b true
*comment CP is short for checkpoint. We will use these twin variables to restore the original ones into the state they were in when we reached the checkpoint for the first time.
*create cp_health 10
*create cp_weapon_a 3
*create cp_weapon_b true
*label start
This label allows us to set our variables to a different state before we reach the checkpoint to simulate some sort of a fight that happens before the checkpoint. For test purposes, we put all posible combinations here:
*choice
#Leave the variables in their original state. [health: 10, weapon_a: 3, weapon_b: true]
*goto checkpoint
#Change health. [health: 7, weapon_a: 3, weapon_b: true]
*set health 7
*goto checkpoint
#Change weapon_a. [health: 10, weapon_a: 2, weapon_b: true]
*set weapon_a 2
*goto checkpoint
#Change weapon_b. [health: 10, weapon_a: 3, weapon_b: false]
*set weapon_b false
*goto checkpoint
#Change health and weapon_a. [health: 7, weapon_a: 2, weapon_b: true]
*set health 7
*set weapon_a 2
*goto checkpoint
#Change health and weapon_b. [health: 7, weapon_a: 3, weapon_b: false]
*set health 7
*set weapon_b false
*goto checkpoint
#Change weapon_a and weapon_b. [health: 10, weapon_a: 2, weapon_b: false]
*set weapon_a 2
*set weapon_b false
*goto checkpoint
#Change health, weapon_a and weapon_b. [health: 7, weapon_a: 2, weapon_b: false]
*set health 7
*set weapon_a 2
*set weapon_b false
*goto checkpoint
*label checkpoint
*comment Now we set our twin variables to the values of the original variables. This way the game memorises the original variables' values. It should be the same no matter how many times we come back to this checkpoint. Every variable that has a chance to be changed between the last checkpoint and the point of death should have a twin variable to be restored (weapons, health, someone we have met between the two points, etc.).
*set cp_health health
*set cp_weapon_a weapon_a
*set cp_weapon_b weapon_b
This is the checkpoint.
This is the current state of our variables:
health: ${health}
*line_break
weapon_a: ${weapon_a}
*line_break
weapon_b: ${weapon_b}
Memorise the states. The next label simulates a battle we die in and it will change the states again. After that, we will return here and the states should be as same as they are now.
*page_break
*label fight
*set health -2
So, lets say we are attacked.
Also, for test purposes, our opponent has made the first move and dealt 2 points of damage to us. Our health is now ${health}. We have a chance to fight back before we die.
*choice
#Attack with weapon_a.
*set weapon_a -1
*goto fight_end
*if (weapon_b) #Attack with weapon_b.
*set weapon_b false
*goto fight_end
*if (weapon_b) #Attack with weapon_a and weapon_b.
*set weapon_a -1
*set weapon_b false
*goto fight_end
*label fight_end
We are dead.
health: ${health}
*line_break
weapon_a: ${weapon_a}
*line_break
weapon_b: ${weapon_b}
We can go back to the checkpoint or restart the game.
*choice
#Go to the checkpoint.
*comment Our twin variables are holding the original variables' values the way they were back when we reached the checkpoint. In the meantime the original variables have changed. To go back to the old values, we set our changed original variables to the twin variables:
*set health cp_health
*set weapon_a cp_weapon_a
*set weapon_b cp_weapon_b
*goto checkpoint
#Restart the game.
*finish