In this next step, we’ll make a separate animation function for the Chest_Lid, the same way you did for the chest.
- In the ChestLidScript, create a new line below the
startOpeningLidAnimation
function. - Create a new, empty function called openChest
- Copy all the code inside the
if(this.startAnimation && !this.stopAnimation)
statement, and paste it into theopenChest
function - Fix indentations using Shift+Tab
- Call the
openChest
function where your code used to be in the tick function, inside theif(this.startAnimation && !this.stopAnimation)
statement.
Tip: Matching Pairs of Brackets
One of the most common bugs that happens when moving TypeScript code around is accidentally missing a { or } curly bracket. The errors that this gives can be very confusing to read, because the order of everything gets jumbled up, but often it will be be something like, “Error: Expected …” or “Error: Unexpected …”
Indenting code is one of the tools we use to visually check that all our pairs of brackets line up.
- Check that each
}
closing curly bracket lines up with the beginning of the line with its{
opening curly bracket
The code editor gives you another way to check, however. If you click a {
or }
curly bracket, it will highlight the other bracket that goes with that pair. If the editor is highlighting the wrong bracket that means there is either a misplaced one between them, or one is missing.