Pick an object at random

0 favourites
  • 4 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • In short-

    -I'd like to make a button that selects a random set of objects and set its position to some where else.

    -the action will be used again on occasions, so an object cannot be selected twice. once it has been picked, it shouldn't be picked again.

    Intended purpose-

    card game

    In detail-

    Say that I have a bib pile of objects in-game, and I want to make a button that will pick one of those objects at random and stick it some where else.

    my first attempted was-

    "I'll make a global variable, and when I click a button, it will set the variable to a random whole number between x-y values. If the value equals the UID number of an object, that object will then be set to position a."

    Problems-

    -if you have about 100 objects, it would be insanely tedious to make a statement that says, "if UID is equal to this global variable, then set position here." for each and every object.

    -once an object is pick, it should not be able to be picked again, this method will not do that because it will still pick any of the same values it used during the last action

    Any suggestions?

  • Try using less objects. like only one and make the back of the card frame 0 and the frame 1 for value 1 etcetera.

    make the random global variable and set the animationframe of the card to the variable.

    I'm not sure if this helps you, but you could just say set card to position a, set animationframe to globalvariable.

  • Hi ry2009,

    From your description, I presume that your objects are all copies of the same thing!

    In which case you could add an instance variable to your object, and set its default to 0. In the system events select the 'Pick random instance' option. This will pick a random instance of any object you specify. Then add a second condition to the 'Pick random instance' event, so it will only pick an object if its instance var is = 0. Once your object has been picked, set its instance variable to 1.

    Hope that helps.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for your replies and suggestions.

    I was able to figure out the issue. So for future reference, based on Blacksmith's suggestion, it would have been nice but the objects I was using where not all the same. It was more of a mix, like having four blue cards, three red, and two green. So it couldn't be applied in this case, but I than read up on how to create a family. What it does is sort of create a hierarchy of objects and so if you assign the solid behavior to the family, all of the objects in that family will have that behavior. After that, I was then able to apply Blacksmith's suggestion to the family. Works like a champ!

    scirra.com/manual/142/families

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