## Entering Program Code

The editor for CindyScript code can be opened by selecting the menu item File/Edit Scripts. When this item is selected, a window for the program code editor is opened. Each construction has an individual program editor window. When first opened, the editor window looks as follows:

The script editor
``

This window contains several components that require explanation. The main part of the window is occupied by a large white space (the middle part of the right side). This is the text field in which you will enter your script later on. The left side of the window is occupied by a "tree view," in which you can select an occasion upon which a script should be executed. The first step in entering a script consists in choosing a suitable occasion.
The lower part of the right side is reserved for console output, while the top part of the window contains some controls and a field in which you can enter a name for your script.

### Entering a Small Script

The first step in entering a script consists in choosing the occasion on which the script is to be executed. For this, one has to click on one of the "Events" shown on the left. Let us choose the "Draw" event. A script entered in the Draw event will always be executed when a drawing is performed on the screen. After this entry has been selected, the main part of the window is free for typing a script. Clicking in the main window allows one to enter the text of the script. In the example shown below a small script was entered and given the title "my first script."

Entering text
``

Pressing the "Play" button executes the script. In the above example a green dotted tine will be drawn consisting of nine simple dots.

### Execution Times

Every script in Cinderella is associated with an occasion on which it will be executed. Since scripts in Cinderella are assumed to run at the runtime of the program, it may well happen that the same script is executed many times during a move. The precise interpretation of the different occasions is described below:

- Draw: A script present in this slot will be executed right before a new screen picture is generated. Scripts entered here will be executed very often. This is the typical place to enter a script that should be automatically updated during a drag of a geometric elements.

- Move: Scripts in this slot will be called even more often than those in the "Draw" slot. They will always be invoked if internally the position of the free elements has changed. In general, this is more often than at screen refresh. Sometimes putting a script in the "Draw" slot produces strange and unexpected results. It might then be good to place it in the "Move" slot.

- Initialization: A script in this slot is executed whenever in the program the parse button of the script editor is pressed. This slot it is very useful for resetting variables or setting points to an initial position.

- Timer Tick: If a script is contained in this slot it will cause an animation controller to be shown in geometric view (if not already present). When the play button of the animation controller is pressed, a script in this slot will be regularly executed every few milliseconds.

- Simulation Start: This script is executed when the animation controller changes from "Stop" to "Play." It is a very good place to enter initial setups for animations.

- Simulation Stop: This script is executed when the animation controller changes from "Play" to "Stop." It is a very good place to evaluate the result of an animation.

- Mouse Down: This slot and the following three slots are very useful for programming under interfaces in CindyScript. A script in this slot is executed whenever the mouse button is pressed. With the function `mouse()` the current mouse coordinates can be read within a script.

- Mouse Up: Scripts in this slot will be executed when the mouse is released.

- Mouse Click: Scripts in this slot will be executed when the mouse is moved.

- Mouse Drag: Scripts in this slot will be executed when the mouse is dragged.

- Key Typed: Scripts in this slot will be executed when the key on the keyboard is pressed. This slot is very useful for handling user input via the keyboard. A string that corresponds to the currently pressed key can be accessed via the `key()` function.

### Control Buttons

In the upper part of the script editor window are two buttons to start and stop the program, as well as a text field to provide names to parts of the program and a language chooser for switching between different languages (at present, only CindyScript is documented).

The script controls
``

Perhaps the most important part of these controls is the "Play" button. Whenever this button is pressed all scripts are parsed and the execution of the program is started. Every change in a program requires the play button to be pressed to become active. Alternatively, the key combination `+` can be used as an equivalent for pressing the play button.
It may happen that a script gets stuck in an infinite loop or performs a calculation that simply takes too long. As a kind of emergency exit, the "Stop" button can be pressed.
The little text field on the left can be used to give a script an individual name. Scripts with different names can be accessed and edited separately.
Finally, there is a dropdown menu for choosing the language for the script. In this documentation you will find all necessary information for programming in CindyScript. However, it is also possible to program in "Python" or in the core Cinderella geometry language. These options will be documented later and elsewhere.

Page last modified on Monday 03 of April, 2006 [16:10:43 UTC].
The original document is available at http://doc.cinderella.de/tiki-index.php?page=Entering%20Program%20Code