Select random instance with instance variable=X

Get help using Construct 2

Post » Tue Sep 11, 2012 3:37 pm

Hi!

I wonder if I can combine the "Pick random instance" with the "Compare instance variable". I'm making a Geography quiz using sprites as questions, and I would like to choose a random sprite from the un-answered ones.

In my test project I see that a mere combination of "Pick random instance" and "Compare instance variable" in same event does not work. Do you think putting one or the other as sub-event would work?
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Tue Sep 11, 2012 3:52 pm

They do work in the same event but you need to change the order to
"compare instance variable" then "pick random instance".
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Tue Sep 11, 2012 6:49 pm

I'm doing that and runs better in that order, but still repeating sometimes (i.e. picking instances without the right instance variable).

Is there a way to detect if there is no instance with the right variable at all? i.e., can I count the result of a "compare instance variable"?

If I can't, then I'll add a counter to detect if all instances have the variable already set.
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Tue Sep 11, 2012 8:29 pm

Maybe your problem is about this issue: http://www.scirra.com/forum/r102-checking-the-instance-variable-is-passing_topic56623.html

When possible, it'll be repaired.
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,192
Reputation: 18,276

Post » Tue Sep 11, 2012 9:43 pm

@arcalaus
You could use the Sprite.PickedCount expression with the system compare condition to see how many are picked.

Those conditions work flawlessly for me. What other events are you using?
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713


Return to How do I....?

Who is online

Users browsing this forum: Pandadoor, Sotir31 and 26 guests