# Arrays and my brain are not compatible - HELP?!

0 favourites
• 8 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
• hi,

so i am new to arrays and i can't wrap my head around them because apparently i am to dumb or something.

either way, what i want is simple, but perhaps i am thinking too complicated.

i want an array that assigns three random, non repeating numbers to seven rows. i got it to work so that each of the seven gets ONE number, but i fail at giving them three numbers.

the idea is it to set up a cluedo style clue sheet. if you ever played cluedo you know what i mean. six players plus one murder get a set of cards each from a pool of 21 cards, so thats three cards per player plus three murder cards. and then you have to cross reference to find out what the murder cards are.

i am not trying to make a cluedo game, i am just trying to get the engine to assign the random cards, in this case numbers, to the seven card holders.

here is the capx of my test:

if you could help me in any way, shape or form to get this to dowhat i want, that would be great^^

• *too dumb (just kidding - my wife is a teacher and I am a terrible speller so I get corrected a lot)

rather than searching every time to see if a "card" has already been picked, it is easier to make a source array with all the available numbers (cards) in it, and delete each one out of the source array as it is dealt to a player...

the SourceDeck is a one dimensional array - with 21 places in it to hold a number.

the PlayerDeck is a two dimensional array that has 7 rows with 3 columns

so, the players (x axis) are numbered 0 to 6, and each one has three (y axis) spots for a card number.

the first players cards are (0,0), (0,1) and (0,2)

second players cards are (1,0), (1,1) and (1,2)

etc...

• i was apparently too dumb/tired to type as well :)

many many thanks, this is exactly what i was hoping for. you have done me a kindness :)

thank you very much for your great help :)

• Thank you for fixing this, but now I have anotehr problem: How do I access those values now? As in, How can I put those values into global variables or something like that?

*too dumb (just kidding - my wife is a teacher and I am a terrible speller so I get corrected a lot)

rather than searching every time to see if a "card" has already been picked, it is easier to make a source array with all the available numbers (cards) in it, and delete each one out of the source array as it is dealt to a player...

the SourceDeck is a one dimensional array - with 21 places in it to hold a number.

the PlayerDeck is a two dimensional array that has 7 rows with 3 columns

so, the players (x axis) are numbered 0 to 6, and each one has three (y axis) spots for a card number.

the first players cards are (0,0), (0,1) and (0,2)

second players cards are (1,0), (1,1) and (1,2)

etc...

• the array is a global "variable".

the part where I print out the results shows how to access the values

PlayerDeck.at(Player#, Card#) will give you any card you want - where player# is a number 0 to 6 representing the player you want, and card# is 0 to 2, for the first, second, or third card.

• I tried that but it always gives me so i think i did something wrong.

basically what i want to do is put them into global variables and check them with each other to determine a random player being the traitor.

like, one player who has the first set of numbers between 1 and 6, the second nmber between 7 and 12 and the third number between 13 and 21 is the traitor. so i figure read all numbers into global variables and make a comparison. but i cant set the global variable...

• ## Try Construct 3

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

Construct 3 users don't see these ads
• ok, the way Cluedo works is you first sort the cards into 3 piles: people, place, and weapon. Take one card from each pile and that goes in an envelope.

then the remaining cards are shuffled together and dealt out to players. The players then have to use the process of elimination to figure out what is in the envelope.

so, to replicate that in Construct, you have to make sure you first get one card from each range (and store those in global variables), and then deal out the remaining cards.

you can't pick the traitor cards after dealing, because you would probably pick cards in different players hands... or you might pick a hand that only has people and places - no weapon.

I updated my sample to show you how I would do it, for any number of players (between 2 and 6).

https://www.rieperts.com/games/forum/Deal21Cards.capx

• you sir, are a saint!

thank you kindly, this is more than i could have hoped for :)

many, many thanks!

• 8 posts