Now that you have created the starting and stopping variables for the chest lid, we should add them to the original chest animation. In this script, we named our variable shouldChestMove
. To make it easier to match, rename that variable to startAnimation
, and change it in the moveChest
function as well.
Tip: Find and Replace
You can easily rename a variable that you have used multiple times in your code using Find and Replace.
You can open this menu using Ctrl+F, or right click to select the Command Palette, and search for ‘find’ to find the search. There are lots of other useful shortcuts in the Command Palette, so it’s worth taking a look.
Once you have the Find menu open, use the drop down arrow to find the Replace field. Enter your original term (shouldChestMove
) in the first text box, and what you want to change it to (startAnimation
) in the second. Pressing Enter in the first text box will just find places in the code that match. Pressing Enter in the second text box will actually change the text to match it.