How can i randomly destroy an object

  • Help me to solve this issue. When i touch anywhere on the screen i want to randomly destroy a blue box from the group, next time another one. Kindly give me detailed answer because iam new to construct. Dont have much knowledge about the terms.

  • Do you know how to generate a random number?

    You need to use a for each loop to set a variable in each object, then on touching the screen, have Construct generate a random number within the range of the numbers of the objects, and destroy that particular one.

    You'll need a variable for the object... for example call it "WhichOne"

    You'll need a loop at start of frame for each object, set the number of the object to the loop index of that loop.

    You'll then need the on screen touch action in another event.. it should generate a random number from zero to the total number of objects.

    Then another loop for each object, if the random number is the same as that variable "which one", then destroy that particular object. and THEN do another loop to re-number them all in their "WhichOne" variable.

    Sorry, I don't have time to make an example file.

  • Try this

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh, well, sure.... if you want to do it the easy way.... ;)

    (I forgot all about the pick random action)

  • Thank you very much...

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