I am looking for 2 examples of a function that returns a value - and how to re use that value.
And what is the best practise to use a function that returns a value?
I could not find any in the tutorial or forum section...
Thanks in advance!
Try the manual entry.
[quote:26dg0304]Returning values from functions
Functions can also return a result. For example, a factorial function could calculate the mathematical result and return it. In an On function event, the return value can be set using the Set return value action.
If the event was called using the Call function action, the returned value is afterwards available using the ReturnValue expression. Functions can also be called directly from an expression using the Call expression; in this case the return value is automatically returned as the result of the Call expression.
And in case you are not familiar with what an expression is: https://www.scirra.com/manual/78/expressions
Develop games in your browser. Powerful, performant & highly capable.
I have this from some other thread. The only thing to remember is that setting the return value does not return from the function at that point - unlike most languages. It only sets up the value to be read when the function ends.
http://www.blackhornettechnologies.com/ ... ample.capx
factorial function example
Thanks for all input!