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

Get help using Construct 2

Post » Thu May 19, 2016 10:12 pm

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? :roll:
Why "set position to another object" does not work?

That's might be helpful (viewtopic.php?f=147&t=173045)

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

Thank you in advance!

Image
Image
B
5
Posts: 22
Reputation: 255

Post » Fri May 20, 2016 3:19 am

add System: Pick random instance to event 12 (use hole as the object to be picked)
B
22
S
4
G
3
Posts: 61
Reputation: 2,683

Post » Fri May 20, 2016 6:26 am

It works! Wow, thank you very much!
B
5
Posts: 22
Reputation: 255

Post » Fri May 20, 2016 6:27 am

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.
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sat May 21, 2016 7:56 am

Awww.. and now it works! :D

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? :roll: 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.

Image

Image
B
5
Posts: 22
Reputation: 255

Post » Sat May 21, 2016 9:23 am

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
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sat May 21, 2016 3:40 pm

@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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon May 23, 2016 6:53 pm

Works fine, thanks! :D

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

Image
Image
B
5
Posts: 22
Reputation: 255


Return to How do I....?

Who is online

Users browsing this forum: Solomon and 11 guests