Bug in arithmatic on Params when recursing with function

Bugs will be moved here once resolved.

Post » Wed Sep 21, 2016 12:38 am

Problem Description
There is a problem with passing function parameters recursively with arithmetic. I suspect it is a type problem but it isn't solved using int() or str().

Attach a Capx
https://1drv.ms/u/s!AjosfNFG8jCjmOQsrzbXcG6GDcnkfA

Description of Capx
The capx has a simple function that shows the it's param value on a text, waits, and then recurses adding 1 to it's param. It doesn't work. It should show 0, 1, 2, 3... instead it shoes 0, 1, 1, 1, 1

There is another version that stores it's param value as a global and then passes the global instead of the param directly. That one works fine.

Steps to Reproduce Bug
  • The functions run automatically at start.

Observed Result
It should show 0, 1, 2, 3...

Expected Result
instead it shoes 0, 1, 1, 1, 1...

Affected Browsers
  • Chrome: ?
  • FireFox: YES
  • Internet Explorer: YES
  • Edge: YES

Operating System and Service Pack
Windows 10

Construct 2 Version ID
233
B
6
S
1
Posts: 22
Reputation: 946

Post » Wed Sep 21, 2016 12:48 am

You can't use Wait in a function. That puts those actions aside and keeps running, so you will have returned from the function before the parameters are accessed.
ImageImageImage
B
71
S
22
G
257
Posts: 3,790
Reputation: 142,696

Post » Wed Sep 21, 2016 3:57 am

You can't use Wait in a function. That puts those actions aside and keeps running, so you will have returned from the function before the parameters are accessed.


I understand what you are saying but the manual gives no indication that the function doesn't remember the parameters during a wait. The section about the wait action specifically mentions that picked instances are remembered during the wait. Construct 2 allows the use of waits in functions and I can imagine a way that the function would work that it would remember them.

I still consider this is a bug unless the documentation clarifies not to use waits in a function or to not expect the function to remember its parameters/local variables.
B
6
S
1
Posts: 22
Reputation: 946

Post » Wed Sep 21, 2016 4:57 am

What if you call some other function within the wait?
Image ImageImage
B
172
S
50
G
182
Posts: 8,439
Reputation: 115,097

Post » Fri Sep 23, 2016 1:18 pm

Closing as this is currently by design: the function call ends immediately after the trigger, and clears its parameters, so if you wait any amount of time the function call has ended and no parameters are available.

People do keep running in to this so I added a note in the tutorial: https://www.scirra.com/tutorials/56/how-to-use-the-system-wait-actions
Scirra Founder
B
402
S
238
G
89
Posts: 24,628
Reputation: 196,023


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests