Sometimes the ways students can interact with your worksheets using the basic features provided by GeoGebra are not powerful enough or too difficult to be used by your students, especially younger ones. GeoGebraScript is there to help you creating simple-to-use constructions with more sophisticated interactivity. It is a simple way to write scripts (small programs) in GeoGebra.
- Checking student's answers by letting them enter their answers into textfields and using scripts to check if they are correct.
- Creating new tasks / challenges after the student pressed a button, either randomly generated or using a set of challenges defined by you.
- Starting animations or revealing new parts of the construction after the student pressed a button or finished his task.
- (and so on..)
There are not only tools to create an object in GeoGebra. You can do the same with commands and the input-bar.
Circle[(1,2),3]you'll get a circle with the center at (1,2) with a radius 3.
Even if you use tools to create an object GeoGebra uses commands in the background to actually create the object. To see the command used to create an object can be found in the Properties Dialog under Definition. So tools are more or less only a help to enter those commands with the mouse. A list of all commands to create an object can be found here.
We've only spoken about commands that create objects so far. The majority of commands create objects, but there are some commands intended to be used in scripts, something we will talk about in more detail later (for the curious, see Scripting Commands).
Basics of Scripting
Scripts are, at heart, just a sequence of GeoGebra commands executed in the following two situations:
- Click: A script is executed after the user clicked on the object.
- Update: A script is executed when the value or properties of the object changed. This may happen if the user moves elements of the construction around, changes sliders, etc.
Now it's time to actually create a script, we will create a silly example using an Update script first:
- First of all, open a blank GeoGebra 4 window
- Now create a point "A" and a line "a". Try out the Line[..] command if you're not familiar with creating objects from the Input Bar.
- Open the On Update tab of the scripting panel as described in the paragraph above.
- Now enter
SetLineThickness[a, Distance[A, a]*2] SetPointSize[A, Distance[A,xAxis]]
as a script, click the OK button (very easy to miss!) and close the dialog.
- Try to figure out what the script does, then check your assumption by moving the point A around!
We've been using the SetLineThickness command to achieve this (unfortunately rather useless) effect, one of those commands intended for scripting we've talked about earlier. At some point you should at least skim the scripting command list to get an idea what's possible with these commands.
You can also find the whole construction in GeoGebra.
If you know something (a little) about scripting: You're help and participation is very welcome! You could add something for the following topics or think of something else:
- More step-by-step instructions for beginners
- Explanation of "scripting objects": Textfields (!!), buttons
- More concrete examples (also links to GeoGebra files using scripting)
Instead of using a showing a slider to go through a step-by-step explanation, you can use a button.
- Create an integer slider, called
- Create a Button using Button Tool
- Enter for caption the visible label on the button
- Enter the script
Steps=Steps + 1
To decrement change "+" to "-". To change the size of the steps change 1 to your value.
Steps=Steps + 1is only available in scripting. If you enter a command like that in the input bar, you'll get an error circular definition