[Help] Making an if structure with various conditions!

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

[Help] Making an if structure with various conditions!

Postby Thooto » Tue May 31, 2011 7:58 am

Hello,

I'm able to make a simple if structure, with only one condition, like "scene.my.x == x ? {xxx} : {xxx}". But I'd like to build something where I must have many conditions, like "scene.my.x == x && scene.my.y == y ? {xxx} : {xxx}". I tried this, but it didn't work! Let's see what I'm talking about :

I spawned three wheels, with three motorized hinges, respectively scene.my.motor1, motor2, motor3 (on motor = true/false). With two lasers I control if they are true or false. There on a third laser I wrote :
Code: Select all
OnLaserHit := (e)=>{scene.my.motor1 == true && scene.my.motor2 == true ? {scene.my.motor3 = true} : {scene.my.motor3 = false}}


So, could you tell me what is wrong in?

Thanks!
Thooto
 
Posts: 45
Joined: Sat Mar 26, 2011 2:02 pm

Re: [Help] Making an if structure with various conditions!

Postby daniels220 » Tue May 31, 2011 6:06 pm

Probably parens around the conditions. Also, if you're checking whether something == true, you don't actually need to compare it to true. So:

Code: Select all
OnLaserHit := (e)=>{ (scene.my.motor1 && scene.my.motor2) ? {scene.my.motor3 = true} : {scene.my.motor3 = false} }


Out of curiosity, does this work?:

Code: Select all
scene.my.motor3 = (scene.my.motor1 && scene.my.motor2)


&& should "return" either true or false, and you should be able to assign it directly. At least, that's what would happen in pretty much any real programming language ever (e.g. C(++), Ruby, JavaScript, etc). somevar = !(somecondition) should also work to negate the whole thing.
daniels220
 
Posts: 95
Joined: Mon Aug 31, 2009 11:30 pm

Re: [Help] Making an if structure with various conditions!

Postby Thooto » Tue May 31, 2011 6:10 pm

Oh thank you so much! Th two codes work.
Thooto
 
Posts: 45
Joined: Sat Mar 26, 2011 2:02 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 5 guests