Choose with exceptions/Dependent Events

Get help using Construct 2

Post » Sat Sep 28, 2013 9:55 pm

I'd like to be able to choose a number from a dynamic list of numbers, I think in probability it's called a dependent event.


I have three sprites (or one sprite and two instances of another sprite to save resources), each sprite needs to choose a number but cannot choose from one already chosen.

For example the list is 0,1,2,3,4

Sprite instances x y and z each choose in order.
X picks 0, so y gets 1,2,3,4, it chooses 3. Now z can choose from 1,2,4 and chooses 4.

so we end with
x 0, y 3, z 4.   

then these are destroyed by going off screen and the new instances can choose from 0,1,2,3,4,


How would I go about doing this?

I've been working on this problem for a few days now and tried using random trees but it just ends up being indecisive and I can't exit the loop because there is always a duplicate. I'd am looking for a way to set up such a dynamic list.Centra2013-09-28 22:14:34
B
10
S
2
Posts: 80
Reputation: 995

Post » Sat Sep 28, 2013 10:23 pm

Try this example. It's basically the same issue, just adapt it to your needs.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Mon Sep 30, 2013 9:22 pm

Thank you very much! I got it working so long as the objects already exist, but my goal is to spawn new sprites, pick frames, then destroy after an interval. it seems that there is something not taken into account when new objects are created because they are always on the same frame, maybe the iids don't reset? How would one take newly created objects into account?Centra2013-09-30 21:31:33
B
10
S
2
Posts: 80
Reputation: 995

Post » Mon Sep 30, 2013 9:34 pm

Working with IID is problematic. It represents an index, starting from zero, of all currently existing instances. If an instance is deleted the IID is arranged new, as well as if instances are added, in a way that the IIDs always range from 0 to # of instances - 1
You could either work with UID which keeps its value, or with an instance variable, to gain better control over the sprites.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Mon Sep 30, 2013 9:41 pm

So I would need to create a function or loop to re-tally all the uids or instance variables to represent the newly created sprites each time they are created and then run the shuffle function that has been edited to look for

Pick Sprite where Sprite.uid/instance var = loopindex?
B
10
S
2
Posts: 80
Reputation: 995

Post » Mon Sep 30, 2013 10:09 pm

That sounds complicated.

The array in the example can be filled with everything, not just a raising number. If you fill it with the UIDs of the sprites/instances in question, and then randomly choose an array index like in the example, it will return the UID.
Pick Sprite where Sprite.UID = array(r)

If I have some time tomorrow, I'll make an enhanced example.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Tue Oct 01, 2013 6:03 am

That would be very good of you, I greatly appreciate it. Handling multiple instances has been my biggest obstacle ever since I started construct, I feel like once I cross this hurdle things will get much easier.

So you are suggesting that the shuffle/choose function takes account of the newly created sprite UIDs each time its run and then picks for them? I'm playing with that idea now trying to figure out the order of operations.

Just a little background:
ultimately i'm going to choose one of those three sprites each shuffle and prevent it from choosing the same frame more than three consecutive times, and remove certain frames from being chosen after they've been called more than 5 times. But I'll figure that out once this "shuffle" is down.

It's essentially an educational game and the player is meant to choose the correct answer, the spite placement is also random(got it covered) so I was wondering if it would be easier to use two sprites, essentially two dummies and a dedicated answer for the shuffle function? Centra2013-10-01 06:10:32
B
10
S
2
Posts: 80
Reputation: 995

Post » Tue Oct 01, 2013 2:15 pm

I just read your post. I already did an example now, but it is more general. On the other hand, you might learn more from it. This example is pretty simple. There's one sprite instance. Whenever you click on any one instance a new instance is created. When you click on the button, three instances will be destroyed. You can mix creation/destroying as you like. The algorithm behind it should be quite obvious. If not please ask.

It just confuses me that you talk of sprites, instances and frames in a way that it all seems to be the same for you. Since those are terms for specific things in C2, I'm not quite sure exactly how the game mechanic will be.

random_unique_selection.capx
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Tue Oct 01, 2013 8:16 pm

deleted due to trouble adding capx linksCentra2013-10-01 20:27:49
B
10
S
2
Posts: 80
Reputation: 995

Post » Tue Oct 01, 2013 8:26 pm

Thank you again for your examples! I will be more careful when I speak of sprites, instances and frames in the future :D

I wanted to know if I was on the right track. I think it's a problem with picking the instances and adding them to the array.

In the first example it will generate random frames but they repeat still have duplicates.



first

in the second I tried adding UIDs to the array but wasn't sure how to pick them.

blockuids.capx
B
10
S
2
Posts: 80
Reputation: 995

Next

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, newt, ST314, tarek2 and 33 guests