So im pretty sure im doing something wrong and I can’t figure this out. Any help is appreciated.
I have a card deck
local cardDeck = {"2S","3S","4S","5S","6S","7S","8S","9S","10S","AS","KS","QS","JS","2H","3H","4H","5H","6H","7H","8H","9H","10H","AH","KH","QH","JH","2C","3C","4C","5C","6C","7C","8C","9C","10C","AC","KC","QC","JC","2D","3D","4D","5D","6D","7D","8D","9D","10D","AD","KD","QD","JD","J1","J2"}
and a shuffle function…
math.randomseed( os.time() )
local function shuffleDeck( t )
local j
for i = #t, 2, -1 do
j = math.random( i )
t[i], t[j] = t[j], t[i]
end
return t
end
and a draw cards function
local currentIndex = 1
function drawCards( num, deck )
local cardsDrawn = {}
for i = currentIndex, num do
cardsDrawn[#cardsDrawn+1] = deck[i]
end
currentIndex = currentIndex + num
return cardsDrawn
end
and a button event
local function pushShuffleButton( event )
cardDeck = shuffleDeck(cardDeck)
print("Drawing CPU cards\n")
cpuHand = drawCards( 27, cardDeck )
print(table.concat(cpuHand,", "))
print("Drawing Player 1 cards\n")
p1Hand = drawCards( 27, cardDeck )
print(table.concat(p1Hand,", "))
end
To see the values in both cpuHand and p1Hand im using the print command. However, the command executes more than 1 time. Any idea why?
My results look something like this
May 05 10:43:18.768 Copyright © 2009-2018 C o r o n a L a b s I n c .
Version: 3.0.0
Build: 2018.3326
May 05 10:43:18.775 Loading project from: ~/Documents/Corona/AP4
May 05 10:43:18.775 Project sandbox folder: ~/Library/Application Support/Corona Simulator/AP4-4638A0329A9F7CE9346821C4FE7FBC3A
May 05 10:43:18.780 Platform: iPhone / x86_64 / 10.15.4 / Intel® Iris™ Graphics 6100 / 2.1 INTEL-14.5.22 / 2018.3326 / en-CA | CA | en_CA | en
May 05 10:43:27.121 Drawing CPU cards
May 05 10:43:27.122 7S, 5H, 4S, J1, 2H, 6S, JS, 3H, JH, AS, AC, 7C, 4H, 6H, QS, 8H, 3C, AD, AH, 8D, JC, J2, 9C, 5S, 3S, KH, 3D
Drawing Player 1 cards
May 05 10:43:27.122 Drawing CPU cardsDrawing Player 1 cards
May 05 10:43:27.129 Drawing CPU cards
May 05 10:43:27.129 Drawing Player 1 cards
May 05 10:43:27.147 Drawing CPU cardsDrawing Player 1 cards
May 05 10:43:27.152 Drawing CPU cards
Drawing Player 1 cards
May 05 10:43:27.168 Drawing CPU cards
May 05 10:43:27.169 Drawing Player 1 cardsDrawing CPU cards Drawing Player 1 cards
May 05 10:43:27.183 Drawing CPU cards
Drawing Player 1 cards
May 05 10:43:27.184 Drawing CPU cards
Drawing Player 1 cards
May 05 10:43:27.185
May 05 10:43:27.201 Drawing CPU cardsDrawing Player 1 cards
May 05 10:43:27.201 Drawing CPU cards
Drawing Player 1 cards
May 05 10:43:27.218 Drawing CPU cards
Drawing Player 1 cards
May 05 10:43:27.218 Drawing CPU cards
Drawing Player 1 cards
Whats happening here?