[Solved] Trouble operating ReturnValue

Get help using Construct 2

Post » Sun Aug 28, 2016 2:13 pm

Image

So, I have a project with two levels of function:
"One" is some basic math operation, here I want it to arbitrary return 10
"Two" 's are different fashion of reusing the formula, here I want it to arbitrary return twice the previous result, so 20

I set the return value of "Two" only once in the code, and yet, it does not return the same value at different point of the code:
- If I call the function from the Outside, it will indeed return 20
- If I request the return value from the Inside of the function, it returns me the same value as "One"? Why?!

Even if put multiple "set returnvalue", the simple fact of requesting a result from another function locks the "inner" returnvalue to the result of that function. If I'd use raw numbers, then requesting the returnvalue from the inside would give me the right result.
Last edited by Estecka on Tue Aug 30, 2016 11:51 am, edited 1 time in total.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Sun Aug 28, 2016 3:23 pm

Image Return 10

Image Return 20
Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896

Post » Sun Aug 28, 2016 3:49 pm

Why is it working this way?! Why does waiting nothing suddenly makes it work?
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Sun Aug 28, 2016 3:52 pm

Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896

Post » Sun Aug 28, 2016 4:12 pm

The problem is the way C2 returns the value. It doesn't really return it, it sets a (global) variable. So the code is the equivalent of:
ReturnValue = 2*ReturnValue
Which of coarse gets confused.
Just use a local variable to store the first return value and set the new return value from it.
Image
ImageImageImage
B
71
S
21
G
232
Posts: 3,696
Reputation: 129,868

Post » Sun Aug 28, 2016 4:41 pm

@Korbaach
So, you mean that if being returned the returnvalue of "One" instead of "Two", it's because the returnvalue of two isn't yet calculated when I request it?
But then :
Image
Shouldn't I be returned 3 in the second case as well, instead of 10 ?

blackhornet wrote:So the code is the equivalent of:
ReturnValue = 2*ReturnValue
Which of coarse gets confused.

Why does it confuse Construct? It's a thing I use all the time and again, for as long as it doesn't involve a function it works perfectly fine:

-Set return value to 10
-Set return value to 2*returnvalue

will properly work, it's

-Set return value to somefunction
-Set return value to 2*returnvalue

that messes up.
I don't really see the relation here.

---
To be clear I have worked around this in my project, at this point what I want is understanding why it behaves in such a weird way.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Mon Aug 29, 2016 12:49 pm

The ReturnValue is not really set on that exact moment that the action is used. The ReturnValue is set on the moment of 'leaving' the function. And available outside the function, it is then by defenition the return of the last called function. It is zero when the Set ReturnValue in the last called function is not used.

So, again by definition, ReturnValue in 'its own function' is never refering to its 'own' ReturnValue.

As blackhornet suggested, use a local variable to evaluate.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Aug 30, 2016 11:51 am

@Instances
Thanks. I had completely misunderstood how Function.ReturnValue was supposed to work.
Somehow I thought it was meant to work inside the function and that it couldn't work outside of it.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, jorgmaquoi, marc254 and 22 guests