New Instance unavailable outside original scope?

0 favourites
  • 8 posts
From the Asset Store
Create your game with this complete pack of images and animations!
  • 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

  • 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.

  • 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" <img src="smileys/smiley17.gif" border="0" align="middle" />

  • 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

  • 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.

  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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<img src="smileys/smiley36.gif" border="0" align="middle" />

  • 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 :D

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)