Thyme If Statement help

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

Thyme If Statement help

Postby MrGlinzz » Tue Jan 28, 2014 9:35 pm

So I've been toying around with chemist's ball on a plane scene, and I figured it'd be nice to add some sort of visual effect to show what way the board is tilting.
I started using a texture, and just following mouse pos but I'm pretty bad at photoshop so gave up on that

Anyways I decided to use squares opacity to show this.
In the update box
Code: Select all
(e)=>{
    app.mousePos(1) >= 0 && app.mousePos(0) <= 0 ? {
        color = {
            [0.0, 0.0, 0.0, ((app.mousePos(0) ^ 2) ^ 0.5) / 4 + ((app.mousePos(1) ^ 2) ^ 0.5) / 4]
        }
    } : {
        color = [0.0, 0.0, 0.0, 0.0]
    }
}


However instead of this code saying "if Ypos >= 0 AND Xpos <= 0 ? {then} : {else}"
I want it to say "if Ypos ?= 0 OR Xpos <=0 ? {then} : {else}"

I had a search on the forums but if and or get excluded from the search... :problem:
And since theres a sign for AND I figured there'd be one for OR?

Thanks!
Mr.G

P.S. Even if I do just use textures (it might look better), this would still be handy to know :)
MrGlinzz
 
Posts: 13
Joined: Tue Mar 19, 2013 11:51 pm

Re: Thyme If Statement help

Postby electronicboy » Wed Jan 29, 2014 1:22 am

Pseudo code:

Code: Select all
IF (CONDITION A) THEN {
//DO SOMETHING
}
ELSE {
    { IF  (CONDITION B) THEN  {
                 //DO SOMETHING
                 }
}


essentially, creating an IF script with the code inside the both of the conditions, so lets do a truth diagram
As you may know, 1 = true, 0 - false

A 1 1 1 0 0
B 0 1 0 1 0
--------------
O 1 1 1 1 0
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: Thyme If Statement help

Postby MrGlinzz » Wed Jan 29, 2014 11:38 am

So in my example would the code be
Code: Select all
(e)=>{
    app.mousePos(1) >= 0 ? {
        color = {
            [0.0, 0.0, 0.0, ((app.mousePos(0) ^ 2) ^ 0.5) / 4 + ((app.mousePos(1) ^ 2) ^ 0.5) / 4]
        }
    } : {
        app.mousePos(0) <= 0 ? {
            color = {
                [0.0, 0.0, 0.0, ((app.mousePos(0) ^ 2) ^ 0.5) / 4 + ((app.mousePos(1) ^ 2) ^ 0.5) / 4]
            }
        } : {
            color = [0.0, 0.0, 0.0, 0.0]
        }
    }
}
MrGlinzz
 
Posts: 13
Joined: Tue Mar 19, 2013 11:51 pm

Re: Thyme If Statement help

Postby electronicboy » Wed Jan 29, 2014 11:45 pm

Yep, that looks like it should work fine!
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: Thyme If Statement help

Postby MrGlinzz » Thu Jan 30, 2014 7:22 pm

Thank youuuu! :thumbup:
MrGlinzz
 
Posts: 13
Joined: Tue Mar 19, 2013 11:51 pm

Re: Thyme If Statement help

Postby s_noonan » Sun Feb 02, 2014 12:34 am

AND = &&
OR = ||
s_noonan
 
Posts: 61
Joined: Tue Mar 30, 2010 2:25 am

Re: Thyme If Statement help

Postby BlockJuice » Sat May 17, 2014 8:00 am

s_noonan wrote:AND = &&
OR = ||


Just use this, OP. That other bit of code is nasty.
BlockJuice
 
Posts: 4
Joined: Mon Jul 22, 2013 1:49 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 3 guests