Alright sorry about that, i’ll try to elaborate. I’m pretty new so my explanations may not be perfectly clear.
First the game deals random cards. Then you should be able to press a button and get dealt more random cards (each time you press the button 1 more random card is dealt).
So for the first card dealt:
[lua]local ran5 = math.random(13) – random number generated to select card.
local function hit (event)
if event.phase == “began” then – This if statement is to select the card based on the random number
print(“ran num is:”, ran5)
if ran5 == 1 then
local ran11 = display.newImage(_1)
ran11.x = _W + 70; ran11.y = 340
elseif ran5 == 2 then
local ran12 = display.newImage(_2)
ran12.x = _W + 70; ran12.y = 340
.
.
.
elseif ran5 == 13 then
local ran23 = display.newImage(_13)
ran23.x = _W + 70; ran23.y = 340
else
print(“error”)
end
if ran5 > 10 then – It is a blackjack game so the jacks, queens etc. have a value of 10
ran5 = 10
end
playerScore:removeSelf() – This is to update the score shown and include the new card
playerScore2 = display.newText(ran3+ran4+ran5, 260,450,nil,15)
elseif event.phase == “ended” or event.phase == “cancelled” then
hitBtn:removeEventListener(“touch”, hit) – Removing event listener for the cards dealt
end
return true
end
hitBtn:addEventListener(“touch”, hit)
– Hit 2
local ran6 = math.random(13)
local function hit2 (event) – The second function to call a second card
if event.phase == “began” then
print(“ran num is:”, ran6)
if ran6 == 1 then
local ran11 = display.newImage(_1)
ran11.x = _W + 90; ran11.y = 340
elseif ran6 == 2 then
local ran12 = display.newImage(_2)
ran12.x = _W + 90; ran12.y = 340
.
.
.
elseif ran6 == 13 then
local ran23 = display.newImage(_13)
ran23.x = _W + 90; ran23.y = 340
else
print(“not”)
end
if ran6 > 10 then
ran6 = 10
end
elseif event.phase == “ended” or event.phase == “cancelled” then
hitBtn:removeEventListener(“touch”, hit2)
end
return true
end
hitBtn:addEventListener(“touch”, hit2)[/lua]
So as you probably know, when the button is touched both of these cards are dealt at the same time. What I am wanting to do is to touch the button and have only the first card, then if the same button is pressed again the second card is then dealt.
I have tried looking around for it but haven’t been able to find anything other than a button dedicated to doing just one thing.
[import]uid: 139423 topic_id: 26208 reply_id: 107150[/import]