Chapter 10. Animal Sounds

In this chapter, you’ll create a simple program to ask players a question and play back sounds based on the answer given. You’ll learn about JavaScript’s switch statement and ScriptCraft’s sounds module. The new program will ask players what their favorite animal is and play back that animal’s sound.

The switch Statement

In Chapter 9 you learned how to get input from players and how to test the input using JavaScript’s if statement. JavaScript provides an additional statement for testing values: the switch statement. The switch statement is useful when you want to make decisions by testing a single value. The switch statement is best explained by example. Create a new file called animalSounds.js in the scriptcraft/plugins/ ...

Get A Beginner’s Guide to Writing Minecraft Plugins in JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.