Donnerstag, 4. September 2014

How to do timing in Etoys?

I just got this question from my students and I thought there might be others with similar interests. So how can I control sequences of actions over time? Say, I want to use speech bubbles to tell a story. I have a number of sentences to show, one after another, and I want to let some time pass between them to give the reader time to read. How can I do that?

Well, I can build a timer and check the time to trigger actions when a certain time is reached. How can I build a timer?

First of all, you need a variable to count time steps. Open the viewer for your object. Create a variable by clicking the "v" - symbol in the top row of the viewer and give your variable a name. I choose "seconds". The default type is "Number", which is fine and 0 decimals places are perfect as well.


Now open a new empty script and drag the tiles to assign a new value to your variable into the script. Change the operation to "increase by" and the number to "1". Make sure the value of your variable is "0" at the start! Name the script "timer".


You do know already that the script, once started, will be executed repeatedly until it is being stopped, right? Do you also know how fast or how slowly this happens? You can see this when you click on the watch in the top row of the scriptor and hold the mouse button down. And you can also change it there! By default, it will be executed 8 times per second. Change this into once per second!



When you now start the script, each second it will increase the value of your variable "seconds" by 1! Now you can use the value of the variable in other scripts:


Use a all-scripts-tile from the supplies to start both, your script and the timer, at the same time and watch :)

Please note: It depends on your computer and what other programs are running on it at the same time, if a second in the Etoys project will be the same as a second at a real clock. It may not be exactly the same, but probably close. It is definitely good enough to control the flow of a story, but for scientific experiments, you should use a real timer!

There is another approach to time handling in this post from Ricardo Moran.

You can also find a tutorial to build a timer in project 6 of the book "Powerful Ideas in the classroom" by Kim Rose and B.J. Allen-Conn.