Picking random object that meets condition

For questions about using Classic.

Post » Tue Apr 26, 2011 4:04 am

Hey all.

I'm not 100% sure how to do this some I'm looking for your guidance.
I have an object "Spark" that is randomly generated inside two or more overlapping instances of object "Wood." I only want one of these instances to be picked to do events. I thought "pick random" would after collision picking work but it's picking a random instance out of all the available instances instead of the ones currently picked by the collision event. [u:3olo4sos]Is there a simple way to pick a random instance within the instances already picked?[/u:3olo4sos]

My code that didn't work:
[code:3olo4sos]object Wood On Collision with Object Spark
object Wood private variable "Flammability">150
object Wood Pick one at random
---->object Wood Set private variable "isBurning" to "Yes" [/code:3olo4sos]

I tried putting the "pick one at random" in a sub-event it it didn't work either. Can you help only one poor wood get picked? :D
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Tue Apr 26, 2011 4:37 am

Looks like "Flammability" is the issue.
You should be able to just change the order with flame able first.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Apr 26, 2011 4:45 am

Awesome Newt, thanks!
Picking is my nemesis because I tend to be a visual person, but it's slowly coming together for me. It works but I'd like to make sense of it. The way my brain thinks about it, in order for the action to fire, all the events have to be true, which in this case they are. Why does switching the collision event and pv event make it work?
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Tue Apr 26, 2011 4:51 am

You only want it to detect the collision when that value is higher. No point detecting a collision with a person, then realising they're already dead.
B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » Tue Apr 26, 2011 5:07 am

[quote="Mulkaccino":2fusuf4t]Awesome Newt, thanks!
Picking is my nemesis because I tend to be a visual person, but it's slowly coming together for me. It works but I'd like to make sense of it. The way my brain thinks about it, in order for the action to fire, all the events have to be true, which in this case they are. Why does switching the collision event and pv event make it work?[/quote:2fusuf4t]

Your welcome.

If I'm not mistaken there are other objects where flammability >150. That event picks those objects.
You have to remember order does matter.
It might help to think of it as filtering. First you start with the bigger number then filter down to what you want.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Apr 26, 2011 6:22 am

Hmm, it still deduces to the same thing in my head. I don't see how Construct is differentiating these two trains of logic:

Scenario 1
Pick objects On Collision
of those objects, Pick those that are flammable
of those objects, pick a random one


and

Scenario 2
Pick those that are flammable
of those objects, pick objects On Collision
of those objects, pick a random one


If what you say is true, than in Scenario 1, all flammable objects are being picked despite what was picked in the collision, why in Scenario 2 wouldn't all the collision objects be picked despite what was picked in the flammable condition?
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Tue Apr 26, 2011 3:41 pm

[quote:2n1epmg8]of those objects, Pick those that are flammable[/quote:2n1epmg8]

But your not doing that. There's no exclusivity, all your doing is adding to the pile, each sub event is just like saying then... do this.
Like if I said choose the two marbles next to each other, then I said choose all the marbles that are within the circle.
In order for your logic to work you would have to add an event to drop any that weren't next to each other.
Or strangely enough place both picking conditions into the same event, rather than separate events. In order to understand how that works you have to think in terms of the conditions rather than the events. Having two conditions like that is like saying "of those", basically and rather than then.
Remember there are two parts to an event, the condition(s), and the action(s).

Hope that makes more sense, and that last parts probably going to confuse the heck out of you.
If your still unsure, I would suggest doing a google for Boolean, and logic operators. :)
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Apr 26, 2011 4:27 pm

Newt,
Thanks for taking the time out of your day to explain it all to me. It was exactly as you said, I was thinking in terms of then instead of and. I can't believe I made it this far in Construct with my flawed logic. Thanks for the clarity!
B
51
S
13
G
8
Posts: 194
Reputation: 7,311


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests