How do I generate a few objects on other objects.. random?

  • Hi!

    I was looking for the answer.. everywhere, but no one can solve my problem in the right way.

    I'm making a very simple game and I need to generate a few objects (random frames) in one time ("for" loop? I think so!) on several other objects. They have to appear once on one object, once in the another.

    Unfortunately, now they begin to generate always in the same place..

    What I'm doing wrong?

    Why "set position to another object" does not work?

    That's might be helpful ()

    Does anyone have an idea how can I solve my problem? What am I doing wrong?

    Thank you in advance!

  • add System: Pick random instance to event 12 (use hole as the object to be picked)

  • It works! Wow, thank you very much!

  • Look at the "set position to object "hole" action. That whole event is not picking any hole in particular via the conditions. Construct 2 events work sometimes in a way where the first instance of an object is picked for an action when meeting event conditions*. This is why Tuiii wrote you need to add a "system: pick a random instance" condition to it. Add it under the "For "create x objects" condition and it should work.

    Edit: *for some actions where the engine expects to use just one object instance instead of multiple from a picked set.

  • Awww.. and now it works!

    However, my game has more bugs.

    I want to draw 3 random elements (without repetition of colors). Construct 2 actually draws me 3 elements, but sometimes imposes them on itself. That's no good. I honestly did not know how to solve this problem.

    It seems to me I have to read the position of object (when it is created), save it in a variable and in the next iteration check that has not previously been used, right? That's is the only thing that comes to my mind.

    My system of comparing frames is not perfect too, because the application always add 1 to the global variable " points" - no matter what object I choose.

    I clean up some code to be more readable.

  • On hole creation assign each hole a unique ID value (or you could just store their IID, I prefer to use my own ID variables rather than the system ones). Store it (push back) that value as a new array element at the X axis, in an array with a default width of 0 and a height of 2. After all holes are created, assign a random number for each X array element at Y=0 (Y=1 will still store your Hole.ID). Sort that array by axis X (it will sort only by values at Y=0, so the random ones) and create objects in a loop that goes through the first three elements and picks each hole by the ID stored "array.at(loopindex,1)".

    The below example will work so long as you have just 3 colours. If you want to pick 3 random colours out of a larger set of colours, things will be a bit more complicated (personally I would do that with yet another array).

    https://www.dropbox.com/s/kv8uhun8anyjo ... .capx?dl=1

  • flementh

    No arrays, just pure carefull picking and some timemanagement.

    No comments in the capx. You look closely to the events and learn, or you ask again for someone to make your code.

    Either way i am fine and happy.

    https://drive.google.com/open?id=0B1SSu ... XNPWXVyams

    Since its touch, it cant work with only a mouse.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Works fine, thanks!

    Objects do not overlap on itself, that's great!

    But I'm still trying to create a system that will draw me colors without repetition (for each iteration).

    Unfortunately it does not work.. I do not know why. Everything seems to be okay..

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