timing before script.

About advanced scenes, and the Thyme scripting language used in Algodoo.

timing before script.

Postby ZHAK » Mon May 10, 2010 1:07 pm

i want to find how to do a timing gap between laser hit each script execute.
I've been searching for a while for it, but i can't find it.
i want to add it to a on laser hit script.:

Code: Select all
(e)=>{
    Scene.addCircle({
        pos := e.pos;
        collideSet := 1;
        radius := 0.05;
    })
}
ZHAK
 
Posts: 1
Joined: Tue Mar 02, 2010 9:18 am

Re: timing before script.

Postby Matten » Mon May 10, 2010 1:22 pm

There are different ways to do this, the one I use:
Code: Select all
(e)=>{scene.my.wait == *waiting time* ? {*code for spawning etc.*; scene.my.wait := *waiting time*}:{scene.my.wait := scene.my.wait - 1}}

You have to declare the variable scene.my.wait with the value *waiting time* in the console first! The waiting time is 40-60 for every sec. So if you want to wait 2 sec. you use the following (First declare the scene.my.wait!)
Code: Select all
(e)=>{scene.my.wait == 100 ? {*code for spawning etc.*; scene.my.wait := 100}:{scene.my.wait := scene.my.wait - 1}}
Cave Johnson wrote:Do you know who I am? I'm the man who's gonna burn your house down! With the lemons! I'm gonna get my engineers to invent a combustible lemon that burns your house down!
User avatar
Matten
 
Posts: 435
Joined: Mon Apr 05, 2010 2:03 pm
Location: The Netherlands

Re: timing before script.

Postby KarateBrot » Mon May 10, 2010 1:24 pm

This for example will spawn your circles exactly every second. Change it to anything you want.
Code: Select all
(e)=>{
    sim.time - controlleracc >= 1 ? {
        Scene.addCircle({
            pos := e.pos;
            collideSet := 1;
            radius := 0.05
        });
        controlleracc = sim.time
    } : {};
    controlleracc > sim.time ? {controlleracc = sim.time} : {}
}



@Matten:
Use = instead of :=
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: timing before script.

Postby Kilinich » Mon May 10, 2010 10:48 pm

You can use my event system for making scheduled tasks.
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 5 guests