Function returning a value

Just started using Construct 2? Post your questions here

Post » Fri Jul 29, 2016 9:04 pm

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!
B
28
S
6
G
7
Posts: 678
Reputation: 5,676

Post » Fri Jul 29, 2016 9:33 pm

Try the manual entry.

https://www.scirra.com/manual/149/function

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
Mistakes were made.
B
52
S
26
G
108
Posts: 1,606
Reputation: 61,133

Post » Fri Jul 29, 2016 9:51 pm

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
ImageImageImage
B
71
S
22
G
240
Posts: 3,732
Reputation: 133,990

Post » Fri Jul 29, 2016 10:29 pm

B
35
S
18
G
14
Posts: 18
Reputation: 9,073

Post » Fri Jul 29, 2016 10:38 pm

Thanks for all input!
B
28
S
6
G
7
Posts: 678
Reputation: 5,676


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest