TimeToLive & OnCollide stuff. (Scripting WHY.)

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

TimeToLive & OnCollide stuff. (Scripting WHY.)

Postby FlareonTheFlareon » Wed Apr 27, 2016 7:10 am

Yay! I'm having another dumb scripting issue! Hopefully, this is one won't be super complicated like the last post I've made.
--

This time, I'm having the issue with TimeToLive section in scripting.

I'm building a teleporter for a marble race, however there's a little kick to it. I want the teleporter to disappear at a certain time when a marble collides into it. So I decided to input the following code in OnCollide:
Code: Select all
(e)=>{
    e.other.pos = scene.my.tpNo0;
    e.this.timeToLive = 15.0
}


Of course, by using TimeToLive, you can make an object instantly disappear on the spot. However, there's an issue I'm having with this. Every time another marble hits the teleporter, the TimeToLive keeps resetting to 15.0 EVERY SINGLE TIME.

So I'm asking you guys if there's anyway for the TimeToLive to keep counting down until it hits 0 and the teleporter disappears. I don't want the TimeToLive to keep resetting for every time a marble hits the teleporter.

I'd love it if you gave me some of sort of code to help me out with this, and please make it SIMPLE as possible. I'm gonna be confused with very huge codes that'll have no idea how to use. I also love it if the teleporter manages to work for every single time until the TimeToLive hits 0.

Thank you, again. :P

Here's a picture of it by the way: Image
Hi. I'm FlareTheFlare, I'm a dude who draws random things on my deviantArt, watches YouTube stuff, & listens to EDM music. So apparently I do stuff in Algodoo too? Mainly it's because I'm interested in creating Marble Races, myself.

Here's my Youtube thing: https://www.youtube.com/channel/UCm5iZH ... RFMZh9yXhA
And my dA thing: http://flareontheflareon.deviantart.com/
User avatar
FlareonTheFlareon
 
Posts: 7
Joined: Sat Mar 26, 2016 9:58 am

Re: TimeToLive & OnCollide stuff. (Scripting WHY.)

Postby Kilinich » Wed Apr 27, 2016 10:40 am

onCollide = (e) => {e.other.pos = scene.my.newPos; timeToLive < 15 ? {}:{timeToLive = 15}}
:thumbup:
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: TimeToLive & OnCollide stuff. (Scripting WHY.)

Postby FlareonTheFlareon » Thu Apr 28, 2016 9:24 am

Kilinich wrote:onCollide = (e) => {e.other.pos = scene.my.newPos; timeToLive < 15 ? {}:{timeToLive = 15}}
:thumbup:


Ah, it worked! Thank you. :)
Hi. I'm FlareTheFlare, I'm a dude who draws random things on my deviantArt, watches YouTube stuff, & listens to EDM music. So apparently I do stuff in Algodoo too? Mainly it's because I'm interested in creating Marble Races, myself.

Here's my Youtube thing: https://www.youtube.com/channel/UCm5iZH ... RFMZh9yXhA
And my dA thing: http://flareontheflareon.deviantart.com/
User avatar
FlareonTheFlareon
 
Posts: 7
Joined: Sat Mar 26, 2016 9:58 am

Re: TimeToLive & OnCollide stuff. (Scripting WHY.)

Postby icrls984 » Fri May 13, 2016 2:22 am

I usually use the script to set the oncollide back to (e)=>{} or a different script when they get hit, so you can make it like
onCollide = (e)=>{e.other.pos=scene.my.newpos;timetolive=15;oncollide=(e)=>{e.other.pos=scene.my.newpos}}
:) Hope this helps!
.
User avatar
icrls984
 
Posts: 80
Joined: Thu Jun 13, 2013 6:33 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 2 guests