How To Create Parameters In Alice

One important aspect here is making sure you remember what a parameter is supposed to do. It's basically a placeholder. It gives you a way to pass information into a method. What is a method? Remember that's just a block of code you've grouped together. This is really helpful if you've got some block of code that together does some larger useful operation that you might want to repeat. This way, you just call the method instead of re-writing the same code over, and over, and over, and over, and over, and...

First things first: create a method before creating your parameters. To do this first highlight the object that you want to have the method. So, if you got some object, like a "chesireCat", and you want to have a method that makes it walk, then you'd highlight the "chesireCat" object in the list of objects. This list is in the upper-left corner of your screen. I have the cheshireCat object selected in the screenshot image below.

Right below the list of objects we get the list of methods available to that cheshireCat object. Notice this list of methods in the picture below. Also note that there are three tabs total: (1) properties, (2) methods, and (3) functions. Right now we can see the available methods because the methods tab is selected. (So, select the other tabs to see properties or functions.)

Now, within the methods tab, click the "create new method" button to create a new method. It will immediately give you a pop-up box to allow you to give a name for the method. Here, I'm going to name my method "walkForward". Notice that it's shown up in my list of methods on the left. It should also appear in it's own tab for methods that you can edit on the right. That's shown in the picture below.

Notice that the tab is labeled "chesireCat.walkForward". That means that the method is called walkForward and it applies to the cheshireCat object. Now, finally, to create a method you'll just have to click the create new parameter button. It's shown on the right of the screen in the picture above. When you do click it, you'll get a pop-up window that looks like the one shown in the picture below.

Within this pop-up window you get to name the parameter and give it's type. In this case I'm going to use the name amount and the type Number. This way I'll take in some amount that I want the cat to move forward (and the name helps me remember what the parameter was supposed to be for). Once your parameter is created there will just be a subtle change to the window. I've captured it in the picture below.

Basically, the name of the parameter just appears a little to the left of the "create new parameter" button. Now that parameter is available for use. To use it, we have to put in some code first. I'll do that with the cheshireCat move method. You'll see the pop-up menu that I used to select this method below.

With that piece of code dropped in, it looks like the picture below.

Right now the code has the cheshireCat walk forward exactly 1 meter. I'm going to change that to have the cat walk forward by the number stored in my parameter, which I called amount. You can select that parameter by clicking on "1 meter" and selecting "amount" from the available menu options, as shown in the picture below.

If you made the selection correctly, then your line of code should look something like the picture below.

Finally, we now need to actually call the method we just created. To do this click on the world.myFirstMethod tab so that you can put code in there. With this tab showing, go to the methods tab for the chesireCat object (you were just there). In that tab we've got the "walkForward" method that we just created. Drag that over into the world.myFirstMethod tab and you can use it just like any other method.

Now, when you click the Play button to play your world, you can see your method in action. This was a very simple (and fairly useless) example for creating a method and using parameters, but it should get you started. It is very difficult to write good code, for large programs, without using methods and parameters so this is indeed an important skill to learn.