what does (a, b, c, d)=>{} mean?

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

what does (a, b, c, d)=>{} mean?

Postby Rideg » Tue Oct 12, 2010 7:33 am

Can someone explain why some script look like
Code: Select all
(e, k, g, u, y)=>{insert script here}
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: what does (a, b, c, d)=>{} mean?

Postby Nait » Tue Oct 12, 2010 9:01 am

This is function, for example
Code: Select all
scene.my.function:=(r,t,u)=>{r=t*u};
scene.my.function(var, 10,13)
// and after this var=130


Ps
Rideg wrote:Want to learn how to script? PM me and I'll teach you the basics and advanced parts of scripting.

And how are you going to teach them? ;)
User avatar
Nait
 
Posts: 224
Joined: Fri Oct 30, 2009 1:56 am
Location: Eastern Russia, Vladivostok

Re: what does (a, b, c, d)=>{} mean?

Postby Matten » Tue Oct 12, 2010 4:41 pm

Nait wrote:Ps
Rideg wrote:Want to learn how to script? PM me and I'll teach you the basics
And how are you going to teach them? ;)

fixed ;)
Cave Johnson wrote:Do you know who I am? I'm the man who's gonna burn your house down! With the lemons! I'm gonna get my engineers to invent a combustible lemon that burns your house down!
User avatar
Matten
 
Posts: 435
Joined: Mon Apr 05, 2010 2:03 pm
Location: The Netherlands

Re: what does (a, b, c, d)=>{} mean?

Postby Rideg » Tue Oct 12, 2010 9:37 pm

Basics should be more exactly I'll change that in a second. When will I have use for this?
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: what does (a, b, c, d)=>{} mean?

Postby Nait » Wed Oct 13, 2010 5:55 am

Hm, when you have to do many identical calculations...
For ex. instead of writing this
Code: Select all
A=((A/180*Math.Pi)+120)/(B^2);
B=((B/180*Math.Pi)+120)/(B^2);
C=((C/180*Math.Pi)+120)/(C^2);
...

You can write this
Code: Select all
func:=(t)=>{t=((t/180*Math.Pi)+120)/(t^2)};
func(A);
func(B);
func(C);
...
User avatar
Nait
 
Posts: 224
Joined: Fri Oct 30, 2009 1:56 am
Location: Eastern Russia, Vladivostok

Re: what does (a, b, c, d)=>{} mean?

Postby tatt61880 » Wed Oct 13, 2010 7:40 am

Nait wrote:You can write this
Code: Select all
func:=(t)=>{t=((t/180*Math.Pi)+120)/(t^2)};
func(A);
func(B);
func(C);
...


1) Please use "Scene.my.".
2) The substitution(t = ...) should be outside of the finction (or use "eval").

It should be like below. ;)
Code: Select all
Scene.my.func:=(t)=>{((t/180*math.pi)+120)/(t^2)};
Scene.my.A = 1;
Scene.my.A = Scene.my.func(Scene.my.A);
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
User avatar
tatt61880
[Most Helpful Person 2010]
 
Posts: 1150
Joined: Mon Aug 31, 2009 5:45 pm
Location: Tokyo, Japan

Re: what does (a, b, c, d)=>{} mean?

Postby Rideg » Wed Oct 13, 2010 7:59 am

Maybe I asked for more than I got. I don't understand. Can you use it in a example? :angel:
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: what does (a, b, c, d)=>{} mean?

Postby Nait » Wed Oct 13, 2010 8:58 am

tatt61880, Okay, I'll take it into consideration :)
(and scene.my can be not used if you are not going so save scene))))
_________


Hm...
For example, you have many color sensors
Code: Select all
scene.my.detect:=(c, d)=>{c==[1.0,1.0,1.0,1.0]?{}:{d.other.density=0}}

And now in every sensor you can write
Code: Select all
oncollide=(e)=>{scene.my.detect(e.other.color, e)}

You can check that, it is working... (in algodoo of course)

PS "in algodoo of course" - deleting object via "density=0"
PSS
Rating: rated 5
Filesize: 14.24 kB
Comments: 0
Ratings: 1
download
User avatar
Nait
 
Posts: 224
Joined: Fri Oct 30, 2009 1:56 am
Location: Eastern Russia, Vladivostok

Re: what does (a, b, c, d)=>{} mean?

Postby KarateBrot » Sun Nov 14, 2010 1:14 pm

Or just a simple mathematical example you can test in your console could also be this:

You got a function f(x) = x² and you want to include it in Algodoo. You can open your console and type in

Code: Select all
scene.my.f := (x) => { x^2 }


or whatever. Press enter and now you can type in scene.my.f(2) for example and your displayed solution would be 4. Or scene.my.f(5) and your solution in the console will be 25. The function always will calculate the square of your input.
You can make pretty complex functions which get calculated dependent from a bunch of variables (or just one in this example).
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: what does (a, b, c, d)=>{} mean?

Postby RA2lover » Sun Nov 28, 2010 12:42 pm

also, you can declare functions inside geometries automatically.
Jrv wrote:
TC42 wrote:Quite honestly, I didn't think anyone on 4chan has that good a use of grammar, spelling, usage, mechanics, ect.
But I've never been there, so I may be wrong.


GTFO newfgt
User avatar
RA2lover
 
Posts: 607
Joined: Mon Aug 31, 2009 8:43 pm
Location: Brazil

Re: what does (a, b, c, d)=>{} mean?

Postby Rideg » Sun Nov 28, 2010 1:20 pm

RA2lover wrote:also, you can declare functions inside geometries automatically.

Sounds interesting. Could you show me an example? :angel:
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: what does (a, b, c, d)=>{} mean?

Postby RA2lover » Wed Dec 01, 2010 7:26 pm

Code: Select all
oncollide=
(e)=>{
e.this.foo=(bar)=>{baz}
}
Jrv wrote:
TC42 wrote:Quite honestly, I didn't think anyone on 4chan has that good a use of grammar, spelling, usage, mechanics, ect.
But I've never been there, so I may be wrong.


GTFO newfgt
User avatar
RA2lover
 
Posts: 607
Joined: Mon Aug 31, 2009 8:43 pm
Location: Brazil


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 7 guests

cron