Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 2: Making Code Respond to Players

Make the Function Stop Early

You don’t have access to this lesson
Please register or sign in to access the course content.

What we want to have happen right now is that if I say “open”, the chest lid opens. If it happens to already open, we want it to do nothing. For that, we can use the keyword return, which stops the function early. 

  1. Add an if-statement that checks if the value of direction was “open” AND the chest’s isOpen property is already true.
  2. Send a message to the console to notify yourself that that happened.
  3. Use return to have the function stop there.
  4. Do the same in an else-if-statement if the value of direction was “close” and the chest’s isOpen property is not true.