Function call applied to non-function

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

Function call applied to non-function

Postby SyntaxError » Sat Apr 30, 2011 9:08 pm

At my latest scene I've got a problem i simply dont get.

I ve created a Seesaw with a box at each end. 2 Lasers constantly point at both boxes. With this script it should ballance automaticly. But whenever scene.my.ballance is exectuted the following error appears:

> Scene.my.ballance
-- Warning: Failed to evaluate: Scene.my.sensor_R_y >= Scene.my.sensor_L_y(?)({Scene.my.ballance_ = false}), Function call applied to non-function: Scene.my.sensor_L_y(?)
-- Warning: Failed to evaluate: Scene.my.sensor_L_y >= Scene.my.sensor_R_y(?)({Scene.my.ballance_ = true}), Function call applied to non-function: Scene.my.sensor_R_y(?)



I do not see any reason why this should happen. I also tryed to change Scene.my.ballance to a function - same problem.

Here is the whole relevant code for this scene.

Code: Select all
Scene.my.sensor_L_y=1;
Scene.my.sensor_R_y=1;
Scene.my.ballance_ = false;

Scene.my.ballance = {
      Scene.my.sensor_R_y>=Scene.my.sensor_L_y ? {
      Scene.my.ballance_  = false;
   };
   Scene.my.sensor_L_y>=Scene.my.sensor_R_y ? {
      Scene.my.ballance_  = true;
   };

};


Code: Select all
Scene.addHinge {
(...)
    ccw := {Scene.my.ballance_};
(...)


Code: Select all
Scene.addBox {
(...)
    onHitByLaser := (e)=>{Scene.my.sensor_L_y=e.pos(1);
(...)
}
Scene.addBox {
(...)
    onHitByLaser := (e)=>{Scene.my.sensor_R_y=e.pos(1);
scene.my.ballance
(...)
Attachments
ballance.phn
(15.97 KiB) Downloaded 33 times
User avatar
SyntaxError
 
Posts: 11
Joined: Sat Apr 30, 2011 9:00 pm

Re: Function call applied to non-function

Postby phunHunger » Sat Apr 30, 2011 10:33 pm

The proper syntax for if then else commands is as follows:
Code: Select all
(evaluation) ? {code to execute if evaluation results as true} : {code to execute if evaluation results as false};


Evaluation is just your comparison like (a>b)

Your code has "if" commands that don't have a ":{}" after the code to execute if the evaluation results as a true.

This...
Code: Select all
Scene.my.sensor_R_y>=Scene.my.sensor_L_y ? {
      Scene.my.ballance_  = false;
   }


Should be this...
Code: Select all
Scene.my.sensor_R_y>=Scene.my.sensor_L_y ? {
      Scene.my.ballance_  = false;
   }:{}


Algodoo is taking your wrong code and changing it to an even more wrong code:
Code: Select all
Scene.my.sensor_R_y >= Scene.my.sensor_L_y(?)({Scene.my.ballance_ = false})


The code above results in the error you are seeing because the compiler thing sees Scene.my.sensor_L_y(?) and thinks you are trying to call a function.

Hope this helps!
Noobs are the best ;)
User avatar
phunHunger
 
Posts: 31
Joined: Mon Apr 26, 2010 10:01 pm

Re: Function call applied to non-function

Postby Someone Else » Sun May 01, 2011 1:56 am

That pretty will explains it. Good job! :thumbup:
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: Function call applied to non-function

Postby SyntaxError » Sun May 01, 2011 11:53 am

Thanks!

Now it works.

Here is the result:
Rating: rated 5.6
Filesize: 32.67 kB
Comments: 2
Ratings: 5
download
User avatar
SyntaxError
 
Posts: 11
Joined: Sat Apr 30, 2011 9:00 pm

Re: Function call applied to non-function

Postby Someone Else » Sun May 01, 2011 7:26 pm

I'd be better if you used e.normal to generate an angle, then performed some simple operation on it and fed that into motorSpeed. The result would be a lot smoother, and would react much faster on a quickly-moving base.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: Function call applied to non-function

Postby SyntaxError » Sun May 01, 2011 10:10 pm

I'd be better if you used e.normal to generate an angle, then performed some simple operation on it and fed that into motorSpeed. The result would be a lot smoother, and would react much faster on a quickly-moving base.


Yes I know. This was jut the first version. I linked the difference between the height of the left and the right box to the speed of the hinge.
User avatar
SyntaxError
 
Posts: 11
Joined: Sat Apr 30, 2011 9:00 pm

Re: Function call applied to non-function

Postby Someone Else » Sun May 01, 2011 11:29 pm

Or rather the direction of the hinge.

Let me know if you need an e.normal >> angle code. I've got a complicated, but good one.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: Function call applied to non-function

Postby bozbez » Mon May 02, 2011 5:31 pm

Image

Go here. Now. That's Now. Not in 5 minutes. Now.
User avatar
bozbez
 
Posts: 149
Joined: Tue Apr 12, 2011 7:01 pm

Re: Function call applied to non-function

Postby Someone Else » Tue May 03, 2011 4:08 pm

I'm not completely sure that one works. Here's mine- call on it onCollide or onLaserHit, it saves the value in controllerAcc.
Code: Select all
{math.asin(e.normal(0)) > 1} ? {controllerAcc = math.acos(e.normal(1))} : {controllerAcc = (-1) * math.acos(e.normal(1))}


Also, Raydeg has a function that is actually shorter than Kilinich's, but gives NaN for just the wrong normal.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 6 guests