Functions with return value?
4 posts • Page 1 of 1
Functions with return value?
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?
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?
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
(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?
The last line of code is the "return value".
all of these will return the same 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.
-
homieeee - Posts: 14
- Joined: Thu Oct 09, 2014 2:13 am
Re: Functions with return value?
Ah, so I guessed more or less right then. Thanks for the info.
- FRA32
- Posts: 229
- Joined: Wed Dec 03, 2014 9:51 pm
4 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 15 guests