[Squeakland] testing with the clock

Scott Wallace scott.wallace at squeakland.org
Mon Mar 20 14:20:19 PST 2006


At 12:52 PM -0500 3/18/06, Thompson, Ryan wrote:
>
>Is there anyway to test whether the clock has been started for the 
>first time? i.e. if I want to introduce a random event that happens 
>initially only at the beginning of the script, how can I test that 
>the clock just started?
>
>Thanks in advance,
>
>Ryan


Hi, Ryan,

One way to address this is to maintain (in the object in question) a 
separate, user-defined, boolean-valued variable, let's call it 
"runYet", whose job is to keep track of whether the script has ever 
been run.

When setting up the simulation, manually set the "runYet" to false.

Near the beginning of the script in question, check the value of 
"runYet"; if it's false, call your special script that introduces the 
desired random event, and in that special script, set the "runYet" 
flag to true, so that the next time the main script is run, it won't 
call the one-time code.

In the "reset" code for getting the simulation back to a suitable 
starting point, be sure to set "runYet" back to false.

Hope this helps,

   -- Scott





More information about the Squeakland mailing list