Introducing Parameters: A Powerful Tool to Level Up Your Code

Hopscotchers, this is a big one: you can now use parameters in your custom rules and custom abilities! Now you can write the code once and use it all over your project.

A parameter is a variable that can be set to a different value each time a custom block is used. You can replace numbers and text in the code inside the custom block with parameters. Then, each time the custom block is used, different values can be used.

Add parameters to your custom rules and abilities

Follow these three simple steps to code with parameters in your custom rules. Or, you can check out some of our existing rules such as “Make A Grid.”

1. When editing a custom ability or rule, you can tap the plus button to add a new parameter.

2. Then you can type the parameter name, and enter a default value. To start with, you could use the number that you had previously been using.

3. When you're ready, you can tap "Save" in the top right corner, to save your changes.

How to use the parameters

1. Find the parameters in the Local Variables section

The parameters that exist for the custom block will show up in the Local variables section on the Variables keyboard. Like other local variables, they will not appear outside the scope where they exist — in this case, they won't show up outside the custom ability or rule where they exist.

2. Pass different values to your custom abilities and rules

When you use the custom ability or rule that you created, you can type a number or text in the bubble next to the parameter name, which will be used as the value of the parameter. Now you can use the block wherever you like in your code, with different parameter values each time. 

3. parameters in a Sample Project

Play this sample project where Chilanna draws a T-shape from two differently sized rectangles using the "Draw rectangle" custom ability.

Learn more about parameters in custom abilities and custom rules in this article.

Download the newest version to try out these exciting features. If you have any questions, please email us at hello@gethopscotch.com.

Happy Hopscotching!

Previous
Previous

New Video Series: Learn how to scale up your code with the power of clones

Next
Next

Link to other Hopscotch projects with the new Open Project block!