Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 2: Making Code Respond to Players

Make the Parameter Optional

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

It’s nice to be very specific about our code, but there may be times when you don’t care, and you just want the lid to switch positions. We can make this possible by using ? after a parameter to make it optional. This means that if you call the function without a parameter, there won’t be any errors.

  • If the chest is open, and the input is “open”, the function stops early and the lid doesn’t do anything.
  • If the chest is closed and the input is “open”, the chest opens.
  • If there is no input, then the function works the way it did before, opening if it was closed, and closing if it was open.