[Help] How to do a if else in a onHitByLaser?

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

[Help] How to do a if else in a onHitByLaser?

Postby vekenti » Tue Jun 30, 2015 4:53 am

I'm trying to make a script that will make a variable 1 if a block is being hit by a laser, and 0 if the block is not, this seems very freaking easy, but I cant figure it out,nor can I find anything on how to do it
vekenti
 
Posts: 13
Joined: Sun Jul 13, 2014 4:43 am

Re: [Help] How to do a if else in a onHitByLaser?

Postby icrls984 » Sat Jul 04, 2015 10:44 pm

Well, I thought about it, and I realized you might be overthinking it. Then I realized how stupid I was thinking this question was easy.:crazy:
I think I have a solution now, onHitByLaser = (e)=>{variable = 1; timeToLive = 1}; postStep = (e)=>{timeToLive < 1 ? {variable = 0; timeToLive = 0.5} : {}}
I hope this solution works, I just tested it and it seemed to work.
.
User avatar
icrls984
 
Posts: 80
Joined: Thu Jun 13, 2013 6:33 am

Re: [Help] How to do a if else in a onHitByLaser?

Postby vekenti » Mon Jul 27, 2015 11:17 pm

thanks alot!
vekenti
 
Posts: 13
Joined: Sun Jul 13, 2014 4:43 am

Re: [Help] How to do a if else in a onHitByLaser?

Postby FRA32 » Tue Aug 04, 2015 12:49 am

I think to do this you first set a boolean variable whenever the laser hits something, and then activate a very short timer to block the Update method. Whenever the timer runs out(because the laser doesnt hit anything anymore) the Update method sets the variable to false. This would look like the following:

onHitByLaser = (e)=>{
e.this._timer = 0.2;
e.this._hitbylaser = true
}

update = (e)=>{
e.this._timer = e.this._timer - 0.1;
e.this._timer <= 0 ? {
e.this._hitbylaser = false
} : {}}
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 7 guests