Functions with return value?

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

Functions with return value?

Postby FRA32 » Mon Aug 10, 2015 11:41 pm

I am coding a little AI driven battle(inspired by ultragamers scene) which runs using various code snipets stored in scene.my.variables and various variables of the entitys. One of these scenes is supposed to return a value so it can be used to decide which one of 2 path points is closer.

Is it possible to add a return value, so that if I type _target = scene.my.getCloserTarget(e.this.pos,"player1") it calls the method I created inside the scene, and thatfor gets the result of the function?
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm

Re: Functions with return value?

Postby FRA32 » Tue Aug 11, 2015 7:00 pm

I think I found an answer myself while tweaking some downloaded scenes:

(a,b,c)=>{
d = a+b+c;
d
}

So it seems just writing a local var name at the end acts as a return
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm

Re: Functions with return value?

Postby homieeee » Tue Aug 11, 2015 9:28 pm

The last line of code is the "return value".

Code: Select all
c = a + b


Code: Select all
c = a + b;
c


Code: Select all
a + b


all of these will return the same value.
User avatar
homieeee
 
Posts: 14
Joined: Thu Oct 09, 2014 2:13 am

Re: Functions with return value?

Postby FRA32 » Tue Aug 11, 2015 11:02 pm

Ah, so I guessed more or less right then. Thanks for the info.
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 15 guests