Function not being executed on first call

Bugs will be moved here once resolved.

Post » Fri Jan 06, 2017 5:45 pm

Problem Description
I have a loop that calls a function when certain criteria are met. In my game, once a screw is "unscrewed" a function is called. However, for some reason the function isn't being executed the first time it's called in the loop.

Attach a Capx
https://drive.google.com/open?id=0B2mi7Z0OwMDqWjEwMlhkLURBRmc

Description of Capx
This is a big project. The issue occurs in the function "addItemToInventory" (look at group "funclib"). The first time the function "checkFasteners" is called inside this function, it does not execute. I tested this by setting up a test var in the function and at the point the function is called. The test var near the call to the function changes, but the test var within the function "checkFasteners" does not until the function has already been called once inside the funtion "addItemToInventory".

Steps to Reproduce Bug
  • Step 1: Walk up to the door control (WASD) and press "R".
  • Step 2: Click on the screw driver and unscrew each of the screws in the face plate by clicking and holding the tip of the screw driver to the screw.
  • Step 3: The var "test" changes when you remove a screw and which calls the "checkFasteners" function and test2 changes when that function is actually executed. You'll see that test2 only increments after the second screw (and all subsequent screws) are removed.

Observed Result
The function is not executed the first time it's called.

Expected Result
The function "checkFasteners" should execute each time it's called.

Affected Browsers
  • Chrome: YES
  • FireFox: YES
  • Internet Explorer: NA

Operating System and Service Pack
Win 7, SP1

Construct 2 Version ID
239 64-bit
B
9
S
1
G
2
Posts: 32
Reputation: 1,974

Post » Fri Jan 06, 2017 7:53 pm

I was able to get this working correctly by calling the function in a different location (and it cleaned my code up in the process). But the issue still exists, and I can't explain why the first time the function was called it wouldn't actually execute.

So, I'll leave it up to you as to whether to close this or not. Thanks.
B
9
S
1
G
2
Posts: 32
Reputation: 1,974

Post » Thu Jan 19, 2017 5:17 pm

Closing, please see the bug report guidelines. This project has 393 events. In all likelihood you just made a mistake in your events. The Function object is mature and well-tested. If you think there is a bug with it, try to reproduce it in a new empty project.
Scirra Founder
B
402
S
238
G
89
Posts: 24,632
Reputation: 196,031

Post » Fri Jan 20, 2017 9:16 pm

@eochranek
The or event on line 323 is unpicking the function object so no function calls will work. The fix is to instead of using the parameter compare condition, use the system compare function.parameter(2)=0.

New bug:
viewtopic.php?f=151&t=186583
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests