Wait Script

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

Wait Script

Postby b2lego » Thu Jun 28, 2018 4:02 pm

Is there a script like "wait 3 seconds" or something of that manner?
b2lego
 
Posts: 5
Joined: Thu Jun 28, 2018 2:59 am

Re: Wait Script

Postby b2lego » Thu Jun 28, 2018 4:08 pm

i did a search and i didnt find anything that fit..
b2lego
 
Posts: 5
Joined: Thu Jun 28, 2018 2:59 am

Re: Wait Script

Postby Skrubs » Fri Jul 06, 2018 2:36 am

Example of a 20 seconds timer that change variable to 1 on object collision:
OnCollide
Code: Select all
(e)=>{timetolive=20}

update
Code: Select all
(e)=>{timetolive<0.02?{timetolive=∞;scene.my.yourvariable=1}:{}}




If you want a script that execute each 10 seconds on object collision for example put the same "timetolive" value in update too example :

OnCollide
Code: Select all
(e)=>{timetolive=10}

update
Code: Select all
(e)=>{timetolive<0.02?{timetolive=10;scene.my.yourvariable=1}:{}}




Or if you want script execute each 10 seconds for example without nothing happend just leave OnCollide empty and set the timetolive to 0.1 like this example:

OnCollide
Code: Select all
(e)=>{}

timeToLive = 0.1
update
Code: Select all
(e)=>{timetolive<0.02?{timetolive=20;yourfunction}:{}}
Skrubs
 
Posts: 16
Joined: Tue Mar 06, 2018 7:36 pm

Re: Wait Script

Postby FRA32 » Sun Aug 05, 2018 1:44 pm

I usually perform time based scripts using a _timer variable(A custom variable added to the object). First you need to enter "_timer=0" into the small black box at the top left of the script menu to register the _timer variable. Then you use it like this:

Somewhere in poststep:

_timer> 0 ? {
_timer = _timer-1/sim.frequency
} : {
_timer > -1 ? {
_timer = -1;
-->{Your script here}<--
} : {}
}

If you want to trigger the timer, just write _timer = X somewhere and replace X with the time until the script should run. Note that this only works with 1 piece of script for each timer, as such you cant just pause any script anywhere, only trigger a specific piece of code after some delay.
FRA32
 
Posts: 227
Joined: Wed Dec 03, 2014 9:51 pm

Re: Wait Script

Postby b2lego » Thu Aug 09, 2018 4:41 pm

Thanks very much that helped a lot
:thumbup:
b2lego
 
Posts: 5
Joined: Thu Jun 28, 2018 2:59 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 6 guests

cron