Picking random object that meets condition

This forum is currently in read-only mode.
  • 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. Is there a simple way to pick a random instance within the instances already picked?

    My code that didn't work:

    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?
  • Looks like "Flammability" is the issue.

    You should be able to just change the order with flame able first.

  • 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?

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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?

    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.

  • 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?

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

    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.

  • 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!

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