[Help] Making an if structure with various conditions!
3 posts • Page 1 of 1
[Help] Making an if structure with various conditions!
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 :
So, could you tell me what is wrong in?
Thanks!
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!
Probably parens around the conditions. Also, if you're checking whether something == true, you don't actually need to compare it to true. So:
Out of curiosity, does this work?:
&& 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.
- 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!
Oh thank you so much! Th two codes work.
- Thooto
- Posts: 45
- Joined: Sat Mar 26, 2011 2:02 pm
3 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 5 guests



