How do I create a random event

  • Let me explain this better.

    So I am working on making a card game (similar to a trading card game)

    I want the turn player when they start their turn to be given a random 5 cards from the dictionary item which is serving as their deck.

    I was thinking of possibly adding a drop down to show what is in their hand.

    So when the game starts each player will get 5 random cards from their deck list placed into their hands.

    So the question here is is there a way to randomize the deck list in its dictionary container, or should I use something else?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's doable of course.

    But as often, it depends on a lot of factors.

    In what you explain you don't mention if you'd expect the player to be able to draw more cards from the deck, or if you'd expect the drawn card to be "removed" from the actual deck.

    So in answer to your current question you want your keys to be named like "Card_1", "Card_2", "Card_3" etc...

    Something like that which is using a number.

    Consider also you are having a dropdown list plugin named "List"

    Then, in an "On start of layout" event, you make a subevent "Repeat 5 times".

    As it action you use the "Add item" action of the object "List" and set it as ("Card_" & int(random(MAX_NB)))

    Where MAX_NB is the greatest number in your dictionary cards + 1.

    This simple event allows you to display on start of layout five random cards taken from dictionary keys.

    To be able to fiddle more precisely and remove cards from the deck so there are no duplicates picked, I'd advised you to look into the Array plugin and possibly this tutorial that helps with making/shuffling and drawing from a deck.

  • It's doable of course.

    But as often, it depends on a lot of factors.

    In what you explain you don't mention if you'd expect the player to be able to draw more cards from the deck, or if you'd expect the drawn card to be "removed" from the actual deck.

    So in answer to your current question you want your keys to be named like "Card_1", "Card_2", "Card_3" etc...

    Something like that which is using a number.

    Consider also you are having a dropdown list plugin named "List"

    Then, in an "On start of layout" event, you make a subevent "Repeat 5 times".

    As it action you use the "Add item" action of the object "List" and set it as ("Card_" & int(random(MAX_NB)))

    Where MAX_NB is the greatest number in your dictionary cards + 1.

    This simple event allows you to display on start of layout five random cards taken from dictionary keys.

    To be able to fiddle more precisely and remove cards from the deck so there are no duplicates picked, I'd advised you to look into the that helps with making/shuffling and drawing from a deck.

    Thank you for the reply.

    Yes they will draw from the deck each new turn. Also there might be up to 4 copies of a card in a deck. So there will be times that a duplicate card is drawn.

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