spawn object on specific places randomly

This forum is currently in read-only mode.
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • i will try to explain what i want to achieve...

    i have five objects and when i click on specific button, i want on one of these object to spawn another object, but randomly and only on one of them. i cant figure it how to do it. i am sure it will not be hard, but for me it is hard to find a solution

  • random spawn

    Hope this helps

    Edit:

    + Button: On Button clicked

    + Items: Pick one at random

    -> Sprite3: Destroy

    -> Items: Spawn object Sprite3 on layer 1 (image point 0)

  • Another appoach:

    Given you have 5 instances, create a pv for the object (e.g. "selector")

    Give the pv the value 0 for the first instance, value 1 for the second, etc, up to the fifth instance, where "selector" gets the value 4

    Then

    + Button: On Button clicked

    ++ Item: "selector" equal to random(5)

    --> Item: Spawn object ...

  • chrisbros: fantastic :) works perfect

    tulamide: i tried also make it this way, it works, but it does not work well, sometimes if i click on button, nothing happens

    thanks much guys for help!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • tulamide: i tried also make it this way, it works, but it does not work well, sometimes if i click on button, nothing happens

    You are absolutely right. The reason for this is a mistake I made. By comparing sprite('selector') with random(5), every single instance is compared to that function, so a new random number is generated per instance, which contradicts the original purpose.

    The right code would involve another variable, e.g. a global var "myRandom"

    + Button: On Button clicked

    -> System: Set global variable 'myRandom' to random(5)

    ++ Item: "selector" equal to random(5)

    --> Item: Spawn object ...

    where ++ Item:... is a subevent to + Button:

    Sorry!

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