Making a Locked Chest#
Here are the steps for making a locked chest:
- Make a new Sprite that looks like a chest and call it
chest. - Make a new Sprite that looks like a coin and call it
coin. - Make a new Sprite that looks like a key and call it
key. - Make a new Item called
coinand give it thecoinSprite. - Make a new Item called
keyand give it thekeySprite. - Make a new Thing called
locked chestand give it thechestSprite. - Add a new Action Sequence to your
locked chestThing. - Add a Make a Decision Action.
- For the If Action, set the condition to
if key >= 1. - For the If Action, add a Do Actions in a Row Action.
- For the first sub-Action, add a Group of Actions Action.
- In the Group of Actions, add an Increase Item Count Action that adds 5 coins.
- In the Group of Actions, after the Increase Item Count, add a Say Something Action that says something like, “You unlocked the chest and found 5 coins!"
- After the Group of Actions, add a Do Nothing Action.
- For the Else Action, add a Say Something Action that says something like, “The chest is locked!”.
- Put a
keyItem in your game and alocked chestin your game. - Hit Play and test it out!
NOTE: Why does this work?
When you walk up to the chest, it first checks to see if you have at least 1 key. If you do, it goes on to the next thing, which is the Group of Actions. The first time you walk up to the chest with a key, the first Action in the Group of Actions will happen, which is to give you 5 coins. The second, and every other time, you walk up to the chest with a key, it will do nothing. However, if you walk up to the chest with no key, it will tell you the chest is locked.
Here is what the Action Sequence should look like:
- Make a Decision
- If - key >= 1
- Do Actions in a Row
- Group of Actions
- Increase Item Count - coin += 5
- Say Something - “You unlocked the chest and found 5 coins!”
- Do Nothing
- Group of Actions
- Do Actions in a Row
- Else
- Say Something - “The chest is locked!”
- If - key >= 1