User Input in SNAP!

In previous blogs, we have covered different aspects of coding practices using a simple Sprite Jump example. In this blog, I will build on top of the code we built in Good Coding Practice: Using Relative Coordinates. Here is what our Sprite Jump code looked like:

User Input

Now let’s say we want the user to tell us what height he/she wants the sprite to jump to. How do we build that in our code?

If you go to Sensing palette, there is an ask block, which asks a question to the user and waits for him/her to respond. Once the user inputs a response, it gets stored in answer block.

User Input - Blocks to Use

Let’s add ask block to the beginning of our code, immediately after User Input - Program Startblock, and replace the jump height by answer block. Please note that in SNAP! to add any block you just need to drag and drop the block to the required location.

Replace the text in ask block to something meaningful, like “Enter the Jump Height.” Or something else that you desire.

This is what the final script should look like:
User Input - Sprite Jump with User Input Height

Now when you click on it, it will ask you for the jump height you want and make the sprite jump to the height you specified.

I hope you found this simple concept easy to grasp. If you any questions/feedback, please leave a comment below.

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *