testing with the clock

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

testing with the clock

Thompson, Ryan
Hello,

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


_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland

winmail.dat (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: testing with the clock

Scott Wallace
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



_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland