How do I pick random instance inside function?

0 favourites
  • 11 posts
From the Asset Store
94 Inside buildings views - Isometric view - PNG transparent - 2048x2048
  • On main event I create many instances of same object.

    I need a Function that will pick a random instance of that object and do something with it.

    If I just use condition Pick random instance inside that Function, nothing will happen. Does it mean that Pick random instance condition is working only at place where those instances are firstly created? (outside function in my case)

  • Should be fine although there is something about waiting until the next tick before picking an instance. If you create and run the function all at the same time then the instances may not exist yet. Also an issue if you pick something outside of a function then run the function it does not keep the picked instance from outside the function, but that doesn't appear to be what you're doing here so that's ok I guess.

  • During debug process it goes this way:

    Inside group

    Events:

    - create instance, create instance, etc.

    - function -> Pick random instance, move it around

    - deactivate group

    in debug window it goes inside function, it circles Pick random instance but, it doesn't apply move action, and it exits from function and deactivates the group. Basically it acts like condition (Pick random instance) was not met.

  • So as mentioned above, are you running create instance then immediately the function underneath? The instances may not exist yet in that tick to pick from. If you add a wait 0 seconds before the function it may work now.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Unfortunately not working. I even extend the wait time and only thing I got is more instances on screen because group is closing after wait time, immediately after function

  • You'll have to share a screenshot of the event sheet to debug this

  • sry for weird naming convention, I am naming most of it in my native language.

    EDIT: I upload another images / chunk for easier following

    final results should be: two different objects that are having same animation frame should overlap.

  • Picking in the function is a little off, try :

    Pick a random object A

    - Indent for sub event, For each object B, object B.animf = object A.animf (not system compare but on the object B compare frame itself), object A set position

  • It still refuses to pick random instance in the function

  • omg, , it works, I was dumb enough not noticing that function was declared inside group which is not being called. I put it outside and now it works. Sometimes it's really hard to follow nested subevents and groups, I wish there is some thicker line to differentiate when you are inside or outside groups and subevents. Thanks a lot for your help!

  • Ok great, glad it's resolved :)

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