Function not keeping object scope?

Discussion and feedback on Construct 2

Post » Sun Dec 02, 2012 5:28 am

I was using the function plugin from rex until upgrading to R111 from R108.2, after which I noticed a few bugs appearing. As an experiment I switched over to the official function plugin but noticed the same behaviour.

The issue seems to be that if I select a sprite and then, in that context, perform an action on it, the code inside the function loses context. Previously this was working fine, but now breaks in both the plugin by rex and the official plugin.

For example, in this code the score only registers as 50 (the first box in the layout), despite there being a second box I am clicking on with a score of 100.


Sample Capx

What I'm curious about is, should I indeed have the scope of the calling event? Or is the function separate from the context of where it is called? Is this something that changed post R108.2?

Cheers!


boolean2012-12-02 05:33:02
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Sun Dec 02, 2012 5:45 am

The list of all changes is available in the changelog of each version.

In your case, in r110.2:
[quote]Bug fix: Function: in some cases the called function would still reference objects picked from the event calling the function. This was not intended; now function events start picking instances from scratch again.[/quote]

Pass the UID of the sprite as a parameter of your function and as a subevent or other condition of the "on" function definition, pick the sprite by UID.Kyatric2012-12-02 05:45:49
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Sun Dec 02, 2012 5:52 am

Thanks Kyatric.

I read the release notes but I think I misunderstood that to mean it was picking objects outside the scope of the calling function (seeing as how I thought the bug it fixed was how it was actually supposed to work). No worries, I'll pass the UID in and repick the object.

Thanks mate.
B
24
S
4
G
1
Posts: 244
Reputation: 3,462


Return to Construct 2 General

Who is online

Users browsing this forum: MadSpy, TRMG and 15 guests