Pick by comparison work not correct with choose(),Pls help!

  • Hi ,

    I use "Pick by comparison" to pick sprite "EF_Start".

    I want to pick random between the sprite "EF_Start" should I set value in value box to chose(1,2) but sometimes Its pick both EF_Start.

    Please help me, What was wrong?

    video hrer: https://youtu.be/6xHRDwSQWWQ

    capx here:https://drive.google.com/file/d/0B8g2b8f9ktNBVGJkN2FEYnVzT0k/view?usp=sharing

  • I think what happens is that when you use one of the "Pick" events, the system actually loops through all instances and compares them one by one.

    So it takes the first instance, compares if .stt=choose(1,2)

    Then it takes the seconds instance, compares if .stt=choose(1,2)

    The problem is that the second time choose(1,2) may give a different number!

    Say for the first instance random number was 1 and for the second instance random number was 2. And as a result, both instances get selected and two bullets are fired!

    Here is an easy fix:

    rand=choose(1,2)

    System-> Pick EF_Start where stt=rand

    Or just use the Pick Random Instance event.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dop2000 thank you, I try your way, its work perfect.

    maybe I really dont understand how to "choose()" work, why two instances? why does event compare 2 times?

  • You have 2 instances of EF_Start.

    When you use "Pick by evaluate" event the system performs 2 steps:

    a) takes the first instance, compares if .stt=choose(1,2)

    b) takes the seconds instance, compares if .stt=choose(1,2)

    Because choose(1,2) expression generates a random number every time, this event works unpredictably. It may pick one instance, or both, or none.

  • dop2000, Wow. now I understand why it campare 2 times. If I have 10 sprites EF_start it will compare 10 times. thank you very much

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