New Instance unavailable outside original scope?

Get help using Construct 2

Post » Fri Jun 28, 2013 12:00 am

I don't think this is a bug so I'm looking for some help; I think this might just be the way C2 handles events

If I call 2 functions, one after the other, it seems that an object created in the first function cant be used in conditions in the second function.

Does this have something to do with C2 waiting until the end of the tick to actually create the object? Or am I bamboozling it up here?

capx example
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Fri Jun 28, 2013 12:13 am

Sounds a lot like the problem I have as well. Wrote a post earlier - Post

I have problems picking them as well. :(

However my problem is in a mouse right click event, but tried the function thing as you are doing as well and that didn't work either.nimos1002013-06-28 00:16:37
B
44
S
11
G
2
Posts: 1,181
Reputation: 6,801

Post » Fri Jun 28, 2013 12:25 am

It sounds like almost the exact same problem! Sounds like it has something to do with the way triggers work.

Maybe a mod can merge our threads once it's determined if this is a "bug" or a "feature"
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Fri Jun 28, 2013 12:30 am

This is by design and has been commented on previously. You can't pick newly created objects outside of the original subevent UNTIL the next top-level event. Add a second On start of layout, and move your ChangeSprite call to there.

One ref: Look at Ashley's comment
ImageImageImage
B
71
S
19
G
180
Posts: 3,482
Reputation: 103,185

Post » Fri Jun 28, 2013 12:38 am

Oooh okay. Le sigh. Thanks blackhornet. I appreciate it!

I might have to do some finagling as in my actual project the two triggers exists eight levels deep.
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Fri Jun 28, 2013 3:29 am

Im a bit confused, so in my event which is triggered by a right click, that create an object and depending on the object that is created, it have to do certain things with it. So for it to work I would have to add an "on create event" and based on a variable or something that could track what is suppose to happen with it, do it in the "on create" event?

And those sub events in my old event,that depend on the state of the object, I would have to move to separate events/functions?nimos1002013-06-28 03:31:04
B
44
S
11
G
2
Posts: 1,181
Reputation: 6,801

Post » Fri Jun 28, 2013 5:34 pm

Hi Nimos,
That sounds about right from what I read; you might have to create a bunch of global variables to make it work.

I think this is the first time I was bugged by a non bug bug in C2. I had a function that was passing 13 parameters up to 80 times in a single tick, so it wasn't realistic for me to make a bunch of global variables or an array. I had to rewrite my code to something less elegant and readable and take a tiny performance hit.

Not like my code is elegant to begin with
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Fri Jun 28, 2013 5:44 pm

Just posted in my original post, that I already tried using a global variable, and it didn't work. Well if I add it in the on create event, I have to click it 2 times, to get an reaction from it. which is not really cool. But ill probably end up just accepting that it doesn't work, and make it some less user friendly way :Dnimos1002013-06-28 17:45:23
B
44
S
11
G
2
Posts: 1,181
Reputation: 6,801


Return to How do I....?

Who is online

Users browsing this forum: bikachu, ikazuchi, irwandwiyanto, thatserafimkid and 2 guests