Pick Object Created in a Function

0 favourites
  • 6 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • I know I have seen the answer to this, but I've tried searching and I've failed miserably to find it. If I have created an object in a function, and I then I want to pick that object. I am creating things procedurally within the function, so I know what family the object is in, but not necessarily the object itself (hence why I can;t just pick it directly)

    Is there a way to pick a family object by using 'Pick Nth' or perhaps by it's IID/UID? I'm sure I remember something like the IID will be -1 or something? I just can't remember, any help appreciated

  • It may help: https://www.scirra.com/tutorials/361/un ... moke-trail

    By the way, I'll explain you the easiest way to pick the object.

    First, you should know its UID or at least something to identify it in the runtime.

    I prefer to use instance variables in the object itself, works great too.

    When you create the object in the function, set the instance variable in the sequence, like this:

    Sample CAPX: https://dl.dropboxusercontent.com/u/470 ... ction.capx

  • Thanks for the reply. Unfortunately I've just realised that I'm coming up against a limitation of Construct 2, which is explained in this thread:

    https://www.scirra.com/forum/viewtopic.php?t=73647&start=0#352637

    As per the explanation in the topic, I can't take any action on the object I just created within the rest of the function, or rather I can but only by explicitly referring to it within its originating subevent

    So I can't do the below (which is just an example of the type of thing I'm, trying to do)

    I realise there are many easy ways to do what I need by putting those global variables under each of the creation subevents, but when there is going to be 100+ then it's just repeating the same code 100 times. I haven't found any easy ways of procedurally creating objects really. I have tried the Wait 0 Seconds, which does sort of work, but when doing things like setting Z Indexes you get a nasty frame of the item being on top and then popping to where it should be.

    I will think of an alternative way to do it

  • I prefer to use events instead of instances, where you're able to setup everything in a visual way, but that's just a personal preference.

    Did you tried to run it once using the "Run Once While True"?

    Without analyzing the whole code I can't help you to workaround it with a different logic.

  • First, use int(random(1,5)) the get the numbers 1 to 4. Second, lookup the Nickname plugin. It will let you name your objects so that they can be created dynamically (use a number as the name in this case). That should help a lot.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • blackhornet I didn't know about the nickname plugin, that looks exactly what I need, thanks!

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