What's wrong with my if statement?

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

What's wrong with my if statement?

Postby Frank » Tue Mar 30, 2010 4:11 am

(e)=>{{e.other.controllerAcc == 4.3}(?)(e.this.color = [1, 1, 1, 1])(:)(e.other.density = 1)}
What the hell is wrong with this onCollide code? I get no error messages or anything. It just doesn't execute. I can't figure out what I'm doing wrong here, and it's very frustrating.
Made some cool stuff a long time ago
User avatar
Frank
[Best Tutorial Maker 2010]
 
Posts: 193
Joined: Mon Aug 31, 2009 6:37 pm
Location: the dark side of the moon

Re: What's wrong with my if statement?

Postby Dakta » Tue Mar 30, 2010 5:01 am

Well, your first problem is that it's not an if statement. What you've got there is a ternary conditional operator.

Aside from that, I have no idea.

And welcome back to the boards Frank!
.. ,__,_____
. / __.==--" - - - - - - - - ""
./#(-'
.`-' From http://www.ascii-art.de/. Modded by me to work in Arial. Image
a Mammoth wrote:be boring and interesting.

Mystery wrote:If you were jailbreaker you shouldn't have when't up the 3.1.3
I didn't know you could go up 3.1.3! Thanks Mystery person!
User avatar
Dakta
 
Posts: 417
Joined: Sat Sep 12, 2009 4:36 pm

Re: What's wrong with my if statement?

Postby Kilinich » Tue Mar 30, 2010 7:44 am

Frank wrote:(e)=>{{e.other.controllerAcc == 4.3}(?)(e.this.color = [1, 1, 1, 1])(:)(e.other.density = 1)}
What the hell is wrong with this onCollide code? I get no error messages or anything. It just doesn't execute. I can't figure out what I'm doing wrong here, and it's very frustrating.



{e.other.controllerAcc == 4.3 ? {e.this.color = [1, 1, 1, 1]} : {e.other.density = 1}}
will work fine.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: What's wrong with my if statement?

Postby xplane80 » Tue Mar 30, 2010 12:58 pm

@frank Did you place the brackets around the ? and : or was it algodoo ?
Image<- Designed by PhysicsGuy
User avatar
xplane80
 
Posts: 498
Joined: Mon Aug 31, 2009 7:28 pm

Re: What's wrong with my if statement?

Postby Frank » Wed Mar 31, 2010 9:07 pm

Algodoo did that.
Thanks Killinich, your script works. I can't figure out what I was doing wrong because I'm pretty sure I started with that, but now it works now and I can continue with my project.
Made some cool stuff a long time ago
User avatar
Frank
[Best Tutorial Maker 2010]
 
Posts: 193
Joined: Mon Aug 31, 2009 6:37 pm
Location: the dark side of the moon

Re: What's wrong with my if statement?

Postby daniels220 » Thu Apr 01, 2010 7:43 pm

Frank, I think the original problem was the parens around the then/else sections, instead of curly braces.
Code: Select all
{if} ? (then) : (else)
instead of
Code: Select all
(if) ? {then} : {else}
. I've noticed that the new (awesome) script menu in 1.7 puts parens around things it doesn't recognize, sometimes, rather than marking them as invalid syntax.
daniels220
 
Posts: 95
Joined: Mon Aug 31, 2009 11:30 pm

Re: What's wrong with my if statement?

Postby Mystery » Fri Apr 02, 2010 12:50 am

Daniel, its always done that.
User avatar
Mystery
 
Posts: 2802
Joined: Thu Sep 03, 2009 1:16 pm
Location: Southern Australia

Re: What's wrong with my if statement?

Postby jessebax129 » Sun Apr 04, 2010 12:02 pm

hey i know it:

(e)=>{your statement == SOMETHING ? {if it is} : {if it is NOT}}

so: (e)=>{ speed1 == speed2 ? {speed1 = speed2} : {speed1 = 10 (for example!!!) }
^^
''=='' can be: == (eaven)
>= (bigger than)
<= (smaller than)
jessebax129
 
Posts: 34
Joined: Tue Jan 05, 2010 6:32 pm

Re: What's wrong with my if statement?

Postby Mystery » Sun Apr 04, 2010 3:19 pm

Well your kind of right, but also horribly wrong.

== Equal To
> More then
< Less then
>= Equal to or More then
<= Equal to or less then
!= Not Equal to

{If}?{Then}:{Else}
If i go to the mall, Then i'll buy shoes or Else i go barefoot :D
User avatar
Mystery
 
Posts: 2802
Joined: Thu Sep 03, 2009 1:16 pm
Location: Southern Australia

Re: What's wrong with my if statement?

Postby Dakta » Thu Apr 08, 2010 9:07 am

But it's not an if statement!

It's more like if conditional evaluates to true ? execute this code : otherwise execute this code

There is a difference you know. And I do have an open suggestion ticket for real if statements, or at least better elseif statements
.. ,__,_____
. / __.==--" - - - - - - - - ""
./#(-'
.`-' From http://www.ascii-art.de/. Modded by me to work in Arial. Image
a Mammoth wrote:be boring and interesting.

Mystery wrote:If you were jailbreaker you shouldn't have when't up the 3.1.3
I didn't know you could go up 3.1.3! Thanks Mystery person!
User avatar
Dakta
 
Posts: 417
Joined: Sat Sep 12, 2009 4:36 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 5 guests