Functions don't register external local variables

Bugs will be moved here once resolved.

Post » Mon Jun 30, 2014 10:27 pm

Problem Description
The capx is simple enough, but basically, it seems that functions don't occur in order with the event sheet when local variables are concerned. I'm not 100% sure that it's actually a bug, but it does seem a little unexpected. Hopefully I didn't waste too much of your time if this isn't a bug, it should be fairly easy to workaround using function parameters.

Description of Capx
Sets the text object to a text value


Observed Result
No text appears

Expected Result
Text appears

Affected Browsers
  • Chrome: (YES)
  • FireFox: (YES)
  • Internet Explorer: (YES)

Operating System and Service Pack
Win7 64bit

Construct 2 Version ID
r173
You do not have the required permissions to view the files attached to this post.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,699

Post » Mon Jun 30, 2014 11:20 pm

Swap actions on event number 2 to 4

Make sure to check "Static" on this local variable.
B
99
S
35
G
29
Posts: 3,139
Reputation: 28,421

Post » Mon Jun 30, 2014 11:35 pm

@joannesalfa well yeah that will work, but this is a simplified capx to show an issue with functions.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,699

Post » Mon Jun 30, 2014 11:48 pm

This isn't a Function issue, it's a Trigger issue.
Manual:
Since triggers run upon an event happening, they aren't checked in top-to-bottom order like other events. This means the ordering of triggers relative to other events is not important (except relative to other triggers of the same type, since triggers still fire top-to-bottom).

A trigger doesn't have any context outside of itself. Just because you place it in a certain location doesn't mean it has context in that location.

Move your 'Text set' to 'On start of layout' - also ignored, since it's a trigger.
ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704

Post » Tue Jul 01, 2014 12:05 am

Right, OK, yeah, I thought as much. Seemed weird to me when I posted this report but that makes sense.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,699

Post » Mon Jul 07, 2014 2:29 pm

This is actually by design. When calling a function, it actually creates a new copy of each non-static local variable to work with at that level of nesting. This is important so recursive functions can use local variables like you can in real programming language: each level of nesting has its own unique local variables which have their own independent values, so each level of logic can work independently.

If you don't want that to happen, the workaround is easy - just make it static.
Scirra Founder
B
403
S
238
G
89
Posts: 24,653
Reputation: 196,143


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 1 guest