How do I create a random event

Get help using Construct 2

Post » Fri Mar 27, 2015 8:11 am

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?
B
4
Posts: 7
Reputation: 221

Post » Fri Mar 27, 2015 1:26 pm

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.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,295
Reputation: 70,795

Post » Fri Mar 27, 2015 3:13 pm

Message: fingaz1 is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
Kyatric wrote: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.
B
4
Posts: 7
Reputation: 221


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, valefor and 12 guests