On/Off OnLaserHit?

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

On/Off OnLaserHit?

Postby Torn » Fri Oct 30, 2009 8:35 am

Hi everyone,

I apologise in advance if this has already been asked - I couldn't find it, but maybe I'm just useless at searching. ;)

If I use OnLaserHit to change a variable, then since it is merely registering a hit it will just change the value, then do nothing else. What I am after is a way to make the laser actually see if it is hitting anything real-time, and change the variable accordingly. This piece of code (It's just made up, it doesn't do anything!) shows what I want to do fairly well, I think:

Code: Select all
(e)=>{LaserHit == true ? {scene.my.whateverthevariableis = 1} : {scene.my.whateverthevariableis = 0}}


Can anyone help me with this?

Thanks,
Torn
Torn
 
Posts: 32
Joined: Tue Sep 01, 2009 8:06 am

Re: On/Off OnLaserHit?

Postby gradyfitz » Fri Oct 30, 2009 9:29 am

Torn wrote:Hi everyone,

I apologise in advance if this has already been asked - I couldn't find it, but maybe I'm just useless at searching. ;)

If I use OnLaserHit to change a variable, then since it is merely registering a hit it will just change the value, then do nothing else. What I am after is a way to make the laser actually see if it is hitting anything real-time, and change the variable accordingly. This piece of code (It's just made up, it doesn't do anything!) shows what I want to do fairly well, I think:

Code: Select all
(e)=>{LaserHit == true ? {scene.my.whateverthevariableis = 1} : {scene.my.whateverthevariableis = 0}}


Can anyone help me with this?

Thanks,
Torn

Using a system involving two lasers, you could build something that checked if the time value (updated by the laser unattached to the object) was before the current time (+ 0.05s or something), and if it was it would change the time.

This isn't built in :), just a note though, in future if you're checking if <x> == true or <x> == false then use just <x> or ! <x> (respectively), the thyme parser will know what you're on about that way (if a man came up to you and asked "is true equal to true?", you might be a bit confused, or if they asked "is true equal to false?").

It is possible if you know what you're doing to calculate these kinds of things and take appropriate action, but it's easier to just use two lasers to get the job done :D.
Mechanisms: 18 Mechanisms.
Thyme: Tutorial - Variables/Commands List.
Thymechanic
gradyfitz
 
Posts: 174
Joined: Tue Sep 01, 2009 8:33 am
Location: Victoria, Australia

Re: On/Off OnLaserHit?

Postby Torn » Fri Oct 30, 2009 11:07 am

Ok, thanks. How would I go about making this time-checking code that you mentioned? I have a reasonable grip on Thyme, but I'm not sure how to approach these more complex things.
Torn
 
Posts: 32
Joined: Tue Sep 01, 2009 8:06 am

Re: On/Off OnLaserHit?

Postby gradyfitz » Sat Oct 31, 2009 12:00 am

Torn wrote:Ok, thanks. How would I go about making this time-checking code that you mentioned? I have a reasonable grip on Thyme, but I'm not sure how to approach these more complex things.

A simple code like
Code: Select all
(e)=>{eval("Scene.my.ExampleValue = {Sim.time < " + (Sim.time + 0.05) + "}")}

would do the trick, it has a 0.05s area for changing to false :D. Hopefully it helps.
Mechanisms: 18 Mechanisms.
Thyme: Tutorial - Variables/Commands List.
Thymechanic
gradyfitz
 
Posts: 174
Joined: Tue Sep 01, 2009 8:33 am
Location: Victoria, Australia

Re: On/Off OnLaserHit?

Postby probber » Thu Jan 14, 2010 10:58 am

Hi
Nice piece of code. But i cant get it to work. So, what i wanna do is that if its TRUE, something is gonna happen, for example a motor speed changes to 5. And if it sets to FALSE the motor speed will be 0. Here is a pic what i mean:
Image
probber
 
Posts: 5
Joined: Tue Sep 15, 2009 9:12 pm
Location: Germany

Re: On/Off OnLaserHit?

Postby standardtoaster » Thu Jan 14, 2010 4:38 pm

In Algodoo booleans are understood. You don't need to compare them to true or false, it will do it for you.
Code: Select all
Scene.my.bool ? {Scene.my.m = 5} : {Scene.my.m = 0}
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: On/Off OnLaserHit?

Postby probber » Fri Jan 15, 2010 12:16 am

Good to know that *g. Thanks, works fine :thumbup:
probber
 
Posts: 5
Joined: Tue Sep 15, 2009 9:12 pm
Location: Germany


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 6 guests

cron