Program not removing cards when face cards clear cards of lesser value

Hey all,

I’ve put a few months of work in this one and I’m stopped on one issue. Everything else is fine and the game engine is complete aside from this. If you need the graphics and sound files for testing this, it’s here. You’re welcome to adapt any tricks I’ve discovered, please just don’t come up with the whole game on the App Store. Zip version If you can fix it I’ll be glad to give you a flat amount from the proceeds.

This is a dice game where a player can roll and move one white die and/or up to two black and/or red dice. When dice on a card exceed the card’s value, the card is captured. White dice can go on any card, red on red only, black on black only. If the yard piles up, the player who caused it loses 15 points. Two “jailbreaks” and that player loses the game. It probably would all make a lot more sense if you could demo it.

If a face card is captured, all cards beneath that card’s value, aces included, are removed from the board.

My problem is that some cards below the value of some face cards aren’t cleared away when a face card is captured. I think the function was called FaceDown, but it’s been ages since I worked on this.

I know this is a flaky request, but my wife’s sick and I’m digging up all my half-done projects. A 5% chance of something helping is better that 0% gathering cobwebs.

Thanks…

[code]
local M={}
require “sprite”
ego = require “ego”
saveFile = ego.saveFile
loadFile = ego.loadFile
function new()
local localGroup = display.newGroup()
local lastChosen=0
backgroundMusic = audio.loadStream(“riot.aiff”)
wrong=audio.loadSound(“wrong.caf”)
slam=audio.loadSound(“slam.caf”)
dealc=audio.loadSound(“dealc.caf”)
qs=audio.loadSound(“quikslam.caf”)
hurryup=audio.loadSound(“hurryace.caf”)
diero=audio.loadSound(“dice.caf”)
display.setStatusBar(display.HiddenStatusBar)
local tdealt=0
_G.tempz=0
local acFace=0
local i=0
local needToDeal=true
local redCount=0
local blackCount=0
local currentDeck = {}
local dealtCards = {}
local tdice=0
local dieOneLock=false
local dieTwoLock=false
local toLock=0
local yardSize=0
local picked=false
local whitelock=false
local inpx={180,280}
local inpy={180,180}
local jokez={“X”,“Y”}
local facez={“J”,“Q”,“K”}
local rankz={“A”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,“J”,“Q”,“K”,“X”,“Y”}
local regz={“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”}
local yard={“B”,“B”,“B”,“B”,“B”,“B”,“B”,“B”}
_G.dicetab={“1”,“1”,“1”,“1”,“1”,“1”}
local aceOr={“ace”,“normal”}
local redz={“D”,“H”}
local sid=0
local acez=0
local blackz={“C”,“S”}
local xcoords={-20,20,-20,20,-20,20}
local ycoords={-48,-48,0,0,48,48}
local frameFlag=0
local chosenDie=0
local poneScore=0
local ptwoScore=0
local lockSheet=sprite.newSpriteSheet(“lock.png”,64,64)
local lockSet=sprite.newSpriteSet(lockSheet,1,2)
sprite.add(lockSet,“lok”,1,2,195,0)
sprite.add(lockSet,“lok2”,1,2,195,0)
local diceSheet = sprite.newSpriteSheet( “wd2.png”, 64, 64)
local diceSet = sprite.newSpriteSet( diceSheet, 1, 12 )
sprite.add( diceSet, “die”, 1, 12, 195, 0)
sprite.add( diceSet, “die2”, 1, 12, 210, 0)
local bSheet = sprite.newSpriteSheet( “bd2.png”, 64, 64)
local bSet = sprite.newSpriteSet( bSheet, 1, 12 )
sprite.add( bSet, “bdie”, 1, 12, 195, 0)
sprite.add( bSet, “bdie2”, 1, 12, 210, 0)
local rSheet = sprite.newSpriteSheet( “rd2.png”, 64, 64)
local rSet = sprite.newSpriteSet( rSheet, 1, 12 )
sprite.add( rSet, “rdie”, 1, 12, 195, 0)
sprite.add( rSet, “rdie2”, 1, 12, 210, 0)
local activeDie=0
local chosenDice=0 – number of dice picked this round.
local landed=false – whether a card has already been targeted
local lastTrgd=0 – last targeted CARD, so as to decrease that value in case of a switch.
local jstTched=0 – id of last card
local thisDie=0
local inPool=0
local lastDie=0 –
local thistot=display.newText(poneScore, 342,170, native.systemFont, 22)
thistot:setTextColor(255, 255, 255)
localGroup:insert(thistot)

local lasttot=display.newText(ptwoScore, 112,170, native.systemFont, 22)
lasttot:setTextColor(255, 255, 255)
localGroup:insert(lasttot)

local hudMsg=display.newText(“0”, 230,140, native.systemFont, 22)
hudMsg:setTextColor(255, 255, 255)
localGroup:insert(hudMsg)
hudMsg.text=“No one won yet”

local dieFrame = display.newImage(“dieframe.png”)
dieFrame.x = 222
dieFrame.y = 222
localGroup:insert(dieFrame)
dieFrame.isVisible=false

local function wdieRead(event)
if event.phase == “ended” and event.target.locked==false then
print (“i’m die 1”)
if needToDeal==false then

if dieOneLock==true then
dieChannel = audio.play( wrong )

– problem – whitelock is not being added to chosen variables.
– should be, else whitelock=true, if chosendice<2 or chosen then…
else
dieTwoLock=true
if chosenDice<2 or event.target.chosen==true then

chosenDie=1
dieFrame.isVisible=true

if event.target.wasRolled==false then

event.target.currentFrame=math.random (1,6)
dieChannel = audio.play( diero )
event.target.value=event.target.currentFrame
dicetab[1]=event.target.currentFrame
thisDie=event.target.currentFrame
event.target.chosen=true
event.target.wasRolled=true
inPool=inPool+1
tdice=1
event.target.holder=inPool
event.target.inPool=1
dieFrame.x=event.target.x
dieFrame.y=event.target.y
chosenDice=chosenDice+1
end

if event.target.inPool~=0 and inPool<3 then
dieFrame.x=event.target.x
dieFrame.y=event.target.y
event.target.x=inpx[event.target.holder]
event.target.y=inpy[event.target.holder]
event.target:toFront()
end

if event.target.currentFrame<7 and inPool<3 then
event.target.currentFrame=event.target.currentFrame+6
dieFrame.isVisible=true
event.target:toFront()
dieFrame.x=event.target.x
dieFrame.y=event.target.y
end
end
end
else
dieChannel = audio.play( wrong )
print (“die selected :P”)
end
end –
end

local function wdieRead2(event)
if event.phase == “ended” and event.target.locked==false then
if needToDeal==false then

if dieTwoLock==true then
dieChannel = audio.play( wrong )

– problem – whitelock is not being added to chosen variables.
– should be, else whitelock=true, if chosendice<2 or chosen then…
else
dieOneLock=true
if chosenDice<2 or event.target.chosen==true then

chosenDie=2
dieFrame.isVisible=true

if event.target.wasRolled==false then
event.target.currentFrame=math.random (1,6)
dieChannel = audio.play( diero )
event.target.value=event.target.currentFrame
dicetab[2]=event.target.currentFrame
thisDie=event.target.currentFrame
event.target.chosen=true
event.target.wasRolled=true
inPool=inPool+1
tdice=1
event.target.holder=inPool
event.target.inPool=1
dieFrame.x=event.target.x
dieFrame.y=event.target.y
chosenDice=chosenDice+1
end

if event.target.inPool~=0 and inPool<3 then
dieFrame.x=event.target.x
dieFrame.y=event.target.y
event.target.x=inpx[event.target.holder]
event.target.y=inpy[event.target.holder]
event.target:toFront()
end

if event.target.currentFrame<7 and inPool<3 then
event.target.currentFrame=event.target.currentFrame+6
dieFrame.isVisible=true
event.target:toFront()
dieFrame.x=event.target.x
dieFrame.y=event.target.y
end
end
end
else
dieChannel = audio.play( wrong )
print (“die selected :P”)
end
end –
end

local die = sprite.newSprite( diceSet )
die.x = 20
die.y = 20
die.xScale=.5
die.yScale=.5
die.value=1
die.lpx=20 – last position in case of a cancel
die.lpy=20
die.locked=false
die.chosen=false
die.previous=0
die:prepare(“die”)
die:addEventListener( “touch”, wdieRead )
localGroup:insert(die)

local function bdieRead(event)
if event.phase==“ended” and event.target.locked==false then
if needToDeal==false then
if blackCount>0 then
if chosenDice<2 or event.target.chosen==true then
chosenDie=3
dieFrame.isVisible=true

if event.target.wasRolled==false then
event.target.currentFrame=math.random (1,6)
dieChannel = audio.play( diero )
event.target.value=event.target.currentFrame
dicetab[3]=event.target.currentFrame
thisDie=event.target.currentFrame
event.target.chosen=true
event.target.wasRolled=true
inPool=inPool+1
tdice=1
event.target.holder=inPool
event.target.inPool=1
dieFrame.x=event.target.x
dieFrame.y=event.target.y
chosenDice=chosenDice+1
end

if event.target.inPool~=0 and inPool<3 then
dieFrame.x=event.target.x
dieFrame.y=event.target.y
event.target.x=inpx[event.target.holder]
event.target.y=inpy[event.target.holder]
event.target:toFront()
end

if event.target.currentFrame<7 and inPool<3 then
event.target.currentFrame=event.target.currentFrame+6
dieFrame.isVisible=true
event.target:toFront()
dieFrame.x=event.target.x
dieFrame.y=event.target.y
end
end
end
else chosenDie=0
end
end
end

local function bdie2Read(event)
print(chosenDice…" chosenDice")
if event.phase==“ended” and event.target.locked==false then
if needToDeal==false then
if blackCount>0 then
if chosenDice<2 or event.target.chosen==true then
chosenDie=4
dieFrame.isVisible=true

if event.target.wasRolled==false then
event.target.currentFrame=math.random (1,6)
dieChannel = audio.play( diero )
event.target.value=event.target.currentFrame
dicetab[4]=event.target.currentFrame
thisDie=event.target.currentFrame
event.target.chosen=true
event.target.wasRolled=true
inPool=inPool+1
tdice=1
event.target.holder=inPool
event.target.inPool=1
dieFrame.x=event.target.x
dieFrame.y=event.target.y
chosenDice=chosenDice+1
end

if event.target.inPool~=0 and inPool<3 then
dieFrame.x=event.target.x
dieFrame.y=event.target.y
event.target.x=inpx[event.target.holder]
event.target.y=inpy[event.target.holder]
event.target:toFront()
end

if event.target.currentFrame<7 and inPool<3 then
event.target.currentFrame=event.target.currentFrame+6
dieFrame.isVisible=true
event.target:toFront()
dieFrame.x=event.target.x
dieFrame.y=event.target.y
end
end
end
else chosenDie=0
end
end
end

local bdie = sprite.newSprite( bSet )
bdie.x = 425
bdie.y = 55
bdie.xScale=.5
bdie.yScale=.5
bdie.wasRolled=false
bdie:prepare(“bdie”)
bdie:addEventListener( “touch”, bdieRead )
bdie.locked=false
bdie.chosen=false
bdie.inPool=0
bdie.value=1
localGroup:insert(bdie)
local bdie2 = sprite.newSprite( bSet )
bdie2.x = 460
bdie2.y = 20
bdie.chosen=false
bdie2:prepare(“bdie2”)
bdie2.xScale=.5
bdie2.yScale=.5
bdie2.wasRolled=false
bdie2.locked=false
bdie2.chosen=false
bdie2.inPool=0
bdie2.value=1
bdie2:addEventListener( “touch”, bdie2Read )
localGroup:insert(bdie2)

local function rdieRead(event)
print(chosenDice…" chosenDice")
if event.phase==“ended” and event.target.locked==false then
if needToDeal==false then
if redCount>0 then
if chosenDice<2 or event.target.chosen==true then
chosenDie=5
dieFrame.isVisible=true

if event.target.wasRolled==false then
event.target.currentFrame=math.random (1,6)
dieChannel = audio.play( diero )
event.target.value=event.target.currentFrame
dicetab[5]=event.target.currentFrame
thisDie=event.target.currentFrame
event.target.chosen=true
event.target.wasRolled=true
inPool=inPool+1
tdice=1
event.target.holder=inPool
event.target.inPool=1
dieFrame.x=event.target.x
dieFrame.y=event.target.y
chosenDice=chosenDice+1
end

if event.target.inPool~=0 and inPool<3 then
dieFrame.x=event.target.x
dieFrame.y=event.target.y
event.target.x=inpx[event.target.holder]
event.target.y=inpy[event.target.holder]
event.target:toFront()
end

if event.target.currentFrame<7 and inPool<3 then
event.target.currentFrame=event.target.currentFrame+6
dieFrame.isVisible=true
event.target:toFront()
dieFrame.x=event.target.x
dieFrame.y=event.target.y
end
end
end
else chosenDie=0
end
end
end

local function rdieRead2(event)
print(chosenDice…" chosenDice")
if event.phase==“ended” and event.target.locked==false then
if needToDeal==false then
if redCount>0 then
if chosenDice<2 or event.target.chosen==true then
chosenDie=6
dieFrame.isVisible=true

if event.target.wasRolled==false then
event.target.currentFrame=math.random (1,6)
dieChannel = audio.play( diero )
event.target.value=event.target.currentFrame
dicetab[6]=event.target.currentFrame
thisDie=event.target.currentFrame
event.target.chosen=true
event.target.wasRolled=true
inPool=inPool+1
tdice=1
event.target.holder=inPool
event.target.inPool=1
dieFrame.x=event.target.x
dieFrame.y=event.target.y
chosenDice=chosenDice+1
end

if event.target.inPool~=0 and inPool<3 then
dieFrame.x=event.target.x
dieFrame.y=event.target.y
event.target.x=inpx[event.target.holder]
event.target.y=inpy[event.target.holder]
event.target:toFront()
end

if event.target.currentFrame<7 and inPool<3 then
event.target.currentFrame=event.target.currentFrame+6
dieFrame.isVisible=true
event.target:toFront()
dieFrame.x=event.target.x
dieFrame.y=event.target.y
end
end
end
else chosenDie=0
end
end
end

local testvar=die.x+50

local die2 = sprite.newSprite( diceSet )
die2.x = 55
die2.y = 55
die2:prepare(“die2”)
die2.xScale=.5
die2.yScale=.5
die2.value=1
die2.lpx=55 – last position in case of a cancel
die2.lpy=55
die2.locked=false
die2.chosen=false
die2:addEventListener( “touch”, wdieRead2 )
localGroup:insert(die2)
local rdie = sprite.newSprite( rSet )
rdie.locked=false
rdie.x = 55
rdie.y = 295
rdie.xScale=.5
rdie.yScale=.5
rdie.chosen=false
rdie:prepare(“rdie”)
rdie:addEventListener( “touch”, rdieRead )
localGroup:insert(rdie)
local rdie2 = sprite.newSprite( rSet )
rdie2.x = 20
rdie2.y = 260
rdie2.xScale=.5
rdie2.yScale=.5
rdie2.locked=false
rdie2.chosen=false
rdie2:prepare(“rdie2”)
rdie2:addEventListener( “touch”, rdieRead2 )
localGroup:insert(rdie2)
local cardPointer=0
local xPoz={240,330,430,330,240,150,50,150}
local yPoz={60,60,160,260,260,260,160,60}
cardCount=0

local btnSheet=sprite.newSpriteSheet( “images/dealmap.png”, 213,40)
local btnSet = sprite.newSpriteSet( btnSheet, 1, 2 )
sprite.add( btnSet, “toss1”, 1, 2, 400, 0)
local btn_Deal = sprite.newSprite( btnSet )
btn_Deal.x = 160
btn_Deal.y = 140
btn_Deal.xScale=.5
btn_Deal.yScale=.5
btn_Deal:prepare(“toss1”)
localGroup:insert(btn_Deal)
btn_Deal.currentFrame=1

local function byeCards() – trash all existing cards.
for i=1,8 do
if dealtCards[i]~=nil then
dealtCards[i]:removeSelf()
dealtCards[i] = nil
– dieChannel = audio.play( qs )
end
end
dealtCards={}
end
local function redCard(event)
if event.phase==“ended” and needToDeal==false then
if tdice>0 and chosenDice<3 then
if chosenDie~=3 and chosenDie~=4 then
print (“initial card filter passed”)
picked=true
event.target:toBack()
if lastTrgd~=0 then
lastTrgd=event.target.ident
else
lastTrgd=event.target.ident
end
if chosenDie==1 then – DEBUG - AND card type matches die type! (C or S instead of D or SP)
dieFrame.isVisible=true
die.x=event.target.x+xcoords[chosenDie]
die.y=event.target.y+ycoords[chosenDie]
die.poz=event.target.ident
if die.locked==false then
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
die:toFront()
end
elseif chosenDie==2 then – DEBUG - AND card type matches die type! (C or S instead of D or SP)
dieFrame.isVisible=true
die2.x=event.target.x+xcoords[chosenDie]
die2.y=event.target.y+ycoords[chosenDie]
die2.poz=event.target.ident
if die.locked==false then
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
die2:toFront()
end
elseif chosenDie==5 then – DEBUG - AND card type matches die type! (C or S instead of D or SP)
dieFrame.isVisible=true
rdie.x=event.target.x+xcoords[chosenDie]
rdie.y=event.target.y+ycoords[chosenDie]
rdie.poz=event.target.ident
if rdie.locked==false then
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
rdie:toFront()
end
elseif chosenDie==6 then
dieFrame.isVisible=true
rdie2.x=event.target.x+xcoords[chosenDie]
rdie2.y=event.target.y+ycoords[chosenDie]
rdie2.poz=event.target.ident
if rdie2.locked==false then
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
rdie2:toFront()
end
else dieChannel = audio.play( wrong )
end
end
end
else print (“rejected”)
end
end

local function blackCard(event)
if event.phase==“ended” and needToDeal==false then
print ("chosendice "…chosenDice)
print (“i’m being touched”)
print (“chosenDie is”…chosenDie)
if tdice>0 and chosenDice<3 then
if chosenDie<5 then
print (“initial card filter passed”)
picked=true
event.target:toBack()
if lastTrgd~=0 then
–dealtCards[lastTrgd].cardT=dealtCards[lastTrgd].cardT-dicetab[chosenDie]
–lasttot.text=dealtCards[lastTrgd].cardT
lastTrgd=event.target.ident
else
lastTrgd=event.target.ident
end
if chosenDie==1 then
dieFrame.isVisible=true
die.x=event.target.x+xcoords[chosenDie]
die.y=event.target.y+ycoords[chosenDie]
if die.locked==false then
die.poz=event.target.ident
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
die:toFront()
end
elseif chosenDie==2 then
dieFrame.isVisible=true
die2.x=event.target.x+xcoords[chosenDie]
die2.y=event.target.y+ycoords[chosenDie]
if die2.locked==false then
die2.poz=event.target.ident
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
die2:toFront()
end
elseif chosenDie==3 then – DEBUG - AND card type matches die type! (C or S instead of D or SP)
dieFrame.isVisible=true
bdie.x=event.target.x+xcoords[chosenDie]
bdie.y=event.target.y+ycoords[chosenDie]
bdie.poz=event.target.ident
if bdie.locked==false then
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
bdie:toFront()
end
elseif chosenDie==4 then
dieFrame.isVisible=true
bdie2.x=event.target.x+xcoords[chosenDie]
bdie2.y=event.target.y+ycoords[chosenDie]
bdie2.poz=event.target.ident
if bdie2.locked==false then
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
bdie2:toFront()
end
else dieChannel = audio.play( wrong )
end
end
end
else print (“rejected”)
end
end

local function jokerCard(event) – end 1
if event.phase==“ended” then
if needToDeal==false then-- end 2
print (tdice)
print (chosenDice)
if tdice>0 and chosenDice<3 then – end 3
picked=true
event.target:toBack()
if lastTrgd~=0 then – end 4
lastTrgd=event.target.ident
else
lastTrgd=event.target.ident
end – end 4
dieFrame.isVisible=true
if chosenDie==1 then – end 5
die.x=event.target.x+xcoords[chosenDie]
die.y=event.target.y+ycoords[chosenDie]
die.poz=event.target.ident
if die.locked==false then
dieFrame:toFront()
die:toFront()
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
end
elseif chosenDie==2 then
die2.x=event.target.x+xcoords[chosenDie]
die2.y=event.target.y+ycoords[chosenDie]
die2.poz=event.target.ident
if die2.locked==false then
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
die2:toFront()
end
elseif chosenDie==3 then – DEBUG - AND card type matches die type! (C or S instead of D or SP)
bdie.x=event.target.x+xcoords[chosenDie]
bdie.y=event.target.y+ycoords[chosenDie]
bdie.poz=event.target.ident
if bdie.locked==false then – end A
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
bdie:toFront()
end – end A
elseif chosenDie==4 then
bdie2.x=event.target.x+xcoords[chosenDie]
bdie2.y=event.target.y+ycoords[chosenDie]
bdie2.poz=event.target.ident
if bdie2.locked==false then – end B
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
bdie2:toFront()
end – end B
elseif chosenDie==5 then
rdie.x=event.target.x+xcoords[chosenDie]
rdie.y=event.target.y+ycoords[chosenDie]
rdie.poz=event.target.ident
if rdie.locked==false then – end C
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
rdie:toFront()
end – end C
elseif chosenDie==6 then
rdie2.x=event.target.x+xcoords[chosenDie]
rdie2.y=event.target.y+ycoords[chosenDie]
rdie2.poz=event.target.ident
if rdie2.locked==false then – end D
dieFrame.x=event.target.x+xcoords[chosenDie]
dieFrame.y=event.target.y+ycoords[chosenDie]
dieFrame:toFront()
rdie2:toFront()
end – end D
end – end 5?
else dieChannel = audio.play( wrong )
end – end 3
end – end 2
end – end 1
end-- end jokercopy

local function reshow() – show all dice and deal button again.
btn_Deal.isVisible=true
die.isVisible=true
die2.isVisible=true
bdie.isVisible=true
bdie2.isVisible=true
rdie.isVisible=true
rdie2.isVisible=true
end

local function aces()
if acez>0 then
acez=acez-2
tdealt=tdealt+1
if yardSize<8 then
yardSize=yardSize+1
dieChannel = audio.play( dealc )
standin=table.indexOf( yard,“B” )
cardPointer=table.indexOf( yard,“B” )
table.remove (yard,standin)
dealtCards[cardPointer] = display.newImage(“images/playingCards/”…currentDeck[cardPointer]…".png")
dealtCards[cardPointer].xScale=.08
dealtCards[cardPointer].yScale=.08
local stibbie=currentDeck[cardPointer]
table.insert(yard,standin,string.sub (stibbie,2))
bie=string.sub(stibbie,1,1)
stibb=string.sub (stibbie,2)
if table.indexOf(redz,bie)~=nil then
dealtCards[cardPointer]:addEventListener( “touch”, redCard )
dealtCards[cardPointer].cardT=0
elseif table.indexOf(blackz,bie)~=nil then
dealtCards[cardPointer]:addEventListener( “touch”, blackCard )
dealtCards[cardPointer].cardT=0
else
dealtCards[cardPointer]:addEventListener( “touch”, jokerCard)
dealtCards[cardPointer].diceT=0
end
dealtCards[cardPointer].x = xPoz[cardPointer]
dealtCards[cardPointer].y = yPoz[cardPointer]
dealtCards[cardPointer].ident=cardPointer
if table.indexOf(facez,stibb)~=nil then
dealtCards[cardPointer].faceRank=table.indexOf(facez,stibb)
tempz=table.indexOf(facez,stibb)
dealtCards[cardPointer].rank=“face”
dealtCards[cardPointer].v=12
dealtCards[cardPointer].s=0
dealtCards[cardPointer].ident=cardPointer
end
if table.indexOf(jokez,stibb)~=nil then
dealtCards[cardPointer].rank=“joker”
dealtCards[cardPointer].josco=0
end
if table.indexOf(regz,stibb)~=nil then
dealtCards[cardPointer].rank=“normal”
dealtCards[cardPointer].v=tonumber(stibb)
dealtCards[cardPointer].s=0
print (“normal card value is”…stibb)
dealtCards[cardPointer].ident=cardPointer
end
if stibb==“A” then
dealtCards[cardPointer].rank=“ace”
bieChannel = audio.play( hurryup )
dealtCards[cardPointer].ident=cardPointer
dealtCards[cardPointer].v=1
dealtCards[cardPointer].s=0
acez=acez+2
end
aces()
else
backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=0, fadein=0 } )
btn_Deal.isVisible=false
dieFrame.isVisible=false
die.isVisible=false
die2.isVisible=false
bdie.isVisible=false
bdie2.isVisible=false
rdie.isVisible=false
rdie2.isVisible=false
die.x = 20
die.y = 20
die2.x = 55
die2.y = 55
bdie.x = 425
bdie.y = 55
bdie2.x = 460
bdie2.y = 20
rdie.x = 55
rdie.y = 295
rdie2.x = 20
rdie2.y = 260
chosenDie=0
chosenDice=0
blackCount=0
redCount=0
blackCount=0
redCount=0
–for i=1,cardPointer do – replace this with a more advanced variable
transition.to( dealtCards[1], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[2], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[3], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[4], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[5], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[6], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[7], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[8], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000), onComplete=byeCards } )
blackCount=0
redCount=0
if poneTurn==true then poneScore=poneScore-15
thistot.text=poneScore
else ptwoScore=ptwoScore-15
lasttot.text=ptwoScore
end
yardSize=0
yard={“B”,“B”,“B”,“B”,“B”,“B”,“B”,“B”}
timer.performWithDelay(3100, reshow, 1)
–end
end
end
end

local function dealaCard()
tdealt=tdealt+1
btn_Deal.isVisible=false
newTurn()
needToDeal=false
if tdealt<55 then
if yardSize<8 then
yardSize=yardSize+1
dieChannel = audio.play( dealc )
standin=table.indexOf( yard,“B” )
cardPointer=table.indexOf( yard,“B” )
table.remove (yard,standin)
print (“Total cards dealt=”…tdealt)
dealtCards[cardPointer] = display.newImage(“images/playingCards/”…currentDeck[tdealt]…".png")
dealtCards[cardPointer].xScale=.08
dealtCards[cardPointer].yScale=.08
local stibbie=currentDeck[tdealt]
table.insert(yard,standin,string.sub (stibbie,2))
bie=string.sub(stibbie,1,1)
stibb=string.sub (stibbie,2)
if table.indexOf(redz,bie)~=nil then
dealtCards[cardPointer]:addEventListener( “touch”, redCard )
redCount=redCount+1
dealtCards[cardPointer].col=“red”
dealtCards[cardPointer].cardT=0
elseif table.indexOf(blackz,bie)~=nil then
dealtCards[cardPointer]:addEventListener( “touch”, blackCard )
dealtCards[cardPointer].cardT=0
blackCount=blackCount+1
dealtCards[cardPointer].col=“black”
else
dealtCards[cardPointer]:addEventListener( “touch”, jokerCard)
blackCount=blackCount+1
redCount=redCount+1
dealtCards[cardPointer].col=“joker”
dealtCards[cardPointer].diceT=0
end
dealtCards[cardPointer].x = xPoz[cardPointer]
dealtCards[cardPointer].y = yPoz[cardPointer]
dealtCards[cardPointer].ident=cardPointer
if table.indexOf(facez,stibb)~=nil then
dealtCards[cardPointer].faceRank=table.indexOf(faces,stibb)
dealtCards[cardPointer].rank=“face”
end

if table.indexOf(jokez,stibb)~=nil then
dealtCards[cardPointer].rank=“joker”
dealtCards[cardPointer].josco=0
end

if table.indexOf(regz,stibb)~=nil then
dealtCards[cardPointer].v=tonumber(stibb)
dealtCards[cardPointer].s=0
dealtCards[cardPointer].rank=“normal”
end
if stibb==“A” then
dealtCards[cardPointer].rank=“ace”
dieChannel = audio.play( hurryup )
dealtCards[cardPointer].v=1
dealtCards[cardPointer].s=0
acez=acez+2
end
aces()
else
secondChannel = audio.play( backgroundMusic, { channel=1, loops=0, fadein=0 } )
dieFrame.isVisible=false
die.isVisible=false
die2.isVisible=false
bdie.isVisible=false
bdie2.isVisible=false
rdie.isVisible=false
rdie2.isVisible=false
die.x = 20
die.y = 20
die2.x = 55
die2.y = 55
bdie.x = 425
bdie.y = 55
bdie2.x = 460
bdie2.y = 20
rdie.x = 55
rdie.y = 295
rdie2.x = 20
rdie2.y = 260
chosenDie=0
chosenDice=0
–for i=1,cardPointer do – replace this with a more advanced variable
btn_Deal.isVisible=false
transition.to( dealtCards[1], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[2], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[3], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[4], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[5], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[6], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[7], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000)} )
transition.to( dealtCards[8], { time=3000, alpha=1, x=300+math.random (-1000,1000), y=500-math.random (0,1000), onComplete=byeCards } )
blackCount=0
redCount=0
yardSize=0
if poneTurn==true then poneScore=poneScore-15
thistot.text=poneScore
else ptwoScore=ptwoScore-15
lasttot.text=ptwoScore
end
yard={“B”,“B”,“B”,“B”,“B”,“B”,“B”,“B”}
timer.performWithDelay(3100, reshow, 1)
–end
end
else
print (“Out of cards!”)
if poneScore>ptwoScore then hudMsg.txt=“Player one won!”
else hudMsg.txt=“Player two won!”
end
end
end

local function shuffleDeck(t)
local n = #t
math.randomseed( os.time() )
while n >= 2 do
local k = math.random(n)
t[n], t[k] = t[k], t[n]
– print(n, t[n])
n = n - 1
end
return t
end

local function resetDeck()

for i=1,cardPointer do – replace this with a more advanced variable
dealtCards[i]:removeSelf()
dealtCards[i] = nil
dieChannel = audio.play( qs )
end

cardPointer=0
–replaceDealtCards()
local deckSize = 52
local suits = {“C”, “D”, “H”, “S”}
local cardVals = {“2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “J”, “Q”, “K”, “A”}
local counter = 0
for i = 1, #suits do
for j = 1, #cardVals do
counter = counter + 1
currentDeck[counter] = suits[i]…cardVals[j]
end
end
currentDeck[53]=“JX”
currentDeck[54]=“JY”
shuffleDeck(currentDeck)
end
–init area
resetDeck()
local poneTurn=true
local poneJails=0
local ptwoJails=0
local whiteCount=0
local poneScore=0
local ptwoScore=0
targetTable={}
offsetX={-30,-30,-30,30,30,30}
offsetY={-30,-30,-30,30,30,30}

function newTurn()
if poneTurn==true then poneTurn=false
btn_Deal.currentFrame=2
else poneTurn=true
btn_Deal.currentFrame=1
end
print (“Active player turn is”…tostring(poneTurn))
lok.currentFrame=1
lok2.currentFrame=1
chosenDice=0
toLock=0
die.chosen=false
die.wasRolled=false
die.inPool=0
die2.chosen=false
die2.wasRolled=false
die2.inPool=0
bdie.chosen=false
bdie.wasRolled=false
bdie.inPool=0
bdie2.chosen=false
bdie2.wasRolled=false
bdie.inPool=0
rdie.inPool=0
rdie.chosen=false
rdie.wasRolled=false
rdie2.chosen=false
rdie2.inPool=0
rdie2.wasRolled=false
inPool=0
dieOneLock=false
dieTwoLock=false
needToDeal=true
end

local function faceDown() – just affects base cards?
for i=1,8 do
if dealtCards[i]~=nil and table.indexOf(aceOr,dealtCards[i].rank)~=nil then – if it’s not an ace or regular
dealtCards[i].s=0 – scrape the die off and add 2.
if dealtCards[i].ident==die.poz then
die.x = 20
die.y = 20
die.poz=0
die.locked=false
die.value=0
die.chosen=false
end

if dealtCards[i].ident==die2.poz then
die2.x = 55
die2.y = 55
die2.poz=0
die2.locked=false
die2.value=0
die2.chosen=false
end

if dealtCards[i].ident==bdie.poz then
bdie.x = 425
bdie.y = 55
bdie.poz=0
bdie.locked=false
bdie.value=0
bdie.chosen=false
end

if dealtCards[i].ident==bdie2.poz then
bdie2.x = 460
bdie2.y = 20
bdie2.poz=0
bdie2.locked=false
bdie2.value=0
bdie2.chosen=false
end

if dealtCards[i].ident==rdie.poz then
rdie.x = 55
rdie.y = 295
rdie.poz=0
rdie.locked=false
rdie.value=0
rdie.chosen=false
end

if dealtCards[i].ident==rdie2.poz then
rdie2.x = 20
rdie2.y = 260
rdie2.poz=0
rdie2.locked=false
rdie2.value=0
rdie2.chosen=false
end

if poneTurn==true then poneScore=poneScore+2
thistot.text=poneScore
else ptwoScore=ptwoScore+2
lasttot.text=ptwoScore
end

if dealtCards[i].col==“red” then
redCount=redCount-1
end

if dealtCards[i].col==“black” then
blackCount=blackCount-1
end

dealtCards[i]:removeSelf()
dealtCards[i] = nil
dieChannel = audio.play( qs )
yard[i]=“B”
yardSize=yardSize-1
cardPointer=i-1
end
end
end

local function scokeep()

die.locked=false
die2.locked=false
bdie.locked=false
bdie2.locked=false
rdie.locked=false
rdie2.locked=false

for i=1,8 do – this should just go through the 1st eight cards - really, what else is there…
–for i=1,cardPointer do – replace this with a more advanced variable
if dealtCards[i]~=nil and dealtCards[i].rank==“joker” then
dealtCards[i].josco=0
if dealtCards[i].ident==die.poz then dealtCards[i].josco=dealtCards[i].josco+1

end
if dealtCards[i].ident==die2.poz then dealtCards[i].josco=dealtCards[i].josco+1

end
if dealtCards[i].ident==bdie.poz then dealtCards[i].josco=dealtCards[i].josco+1

end
if dealtCards[i].ident==bdie2.poz then dealtCards[i].josco=dealtCards[i].josco+1

end
if dealtCards[i].ident==rdie.poz then dealtCards[i].josco=dealtCards[i].josco+1

end
if dealtCards[i].ident==rdie2.poz then dealtCards[i].josco=dealtCards[i].josco+1

end
if dealtCards[i].josco>=5 then
blackCount=blackCount-1
redCount=redCount-1
if dealtCards[i].ident==die.poz then – DEBUG - transfer the muted above.
die.x = 20
die.y = 20
die.poz=0

die.value=0
die.chosen=false
end
if dealtCards[i].ident==die2.poz then
die2.x = 55
die2.y = 55
die2.poz=0
die2.value=0
die2.chosen=false
end
if dealtCards[i].ident==bdie.poz then
bdie.x = 425
bdie.y = 55
bdie.poz=0
bdie.value=0
bdie.chosen=false
end
if dealtCards[i].ident==bdie2.poz then
bdie2.x = 460
bdie2.y = 20
bdie2.poz=0
bdie2.value=0
bdie2.chosen=false
end
if dealtCards[i].ident==rdie.poz then
rdie.x = 55
rdie.y = 295
rdie.poz=0
rdie.value=0
rdie.chosen=false
end
if dealtCards[i].ident==rdie2.poz then
rdie2.x = 20
rdie2.y = 260
rdie2.poz=0
rdie2.value=0
rdie2.chosen=false
end
dealtCards[i]:removeSelf()
dealtCards[i] = nil
dieChannel = audio.play( qs )
– print (“joker card pos is”…i)
yard[i]=“B”
yardSize=yardSize-1
cardPointer=i-1

if poneTurn==true then poneScore=poneScore+25
thistot.text=poneScore
else ptwoScore=ptwoScore+25
lasttot.text=ptwoScore
end

else
–dealtCards[i].josco=0
end

elseif dealtCards[i]~=nil and table.indexOf(aceOr,dealtCards[i].rank)~=nil then

---- START LAST SCORiNG
dealtCards[i].s=0
if dealtCards[i].ident==die.poz then dealtCards[i].s=dealtCards[i].s+die.value
end
if dealtCards[i].ident==die2.poz then dealtCards[i].s=dealtCards[i].s+die2.value
end
if dealtCards[i].ident==bdie.poz then dealtCards[i].s=dealtCards[i].s+bdie.value
end
if dealtCards[i].ident==bdie2.poz then dealtCards[i].s=dealtCards[i].s+bdie2.value
end
if dealtCards[i].ident==rdie.poz then dealtCards[i].s=dealtCards[i].s+rdie.value
end
if dealtCards[i].ident==rdie2.poz then dealtCards[i].s=dealtCards[i].s+rdie2.value
end
print (“face score is”…dealtCards[i].s)
if tonumber(dealtCards[i].s)>tonumber(dealtCards[i].v) then
if dealtCards[i].ident==die.poz then – DEBUG - transfer the muted above.
die.x = 20
die.y = 20
die.poz=0
die.locked=false
die.value=0
die.chosen=false
end

if dealtCards[i].ident==die2.poz then
die2.x = 55
die2.y = 55
die2.poz=0
die2.locked=false
die2.value=0
die2.chosen=false
end

if dealtCards[i].ident==bdie.poz then
bdie.x = 425
bdie.y = 55
bdie.poz=0
bdie.locked=false
bdie.value=0
bdie.chosen=false
end

if dealtCards[i].ident==bdie2.poz then
bdie2.x = 460
bdie2.y = 20
bdie2.poz=0
bdie2.locked=false
bdie2.value=0
bdie2.chosen=false
end

if dealtCards[i].ident==rdie.poz then
rdie.x = 55
rdie.y = 295
rdie.poz=0
rdie.locked=false
rdie.value=0
rdie.chosen=false
end

if dealtCards[i].ident==rdie2.poz then
rdie2.x = 20
rdie2.y = 260
rdie2.poz=0
rdie2.locked=false
rdie2.value=0
rdie2.chosen=false
end
acFace=dealtCards[i].ident
if dealtCards[i].col==“red” then
redCount=redCount-1
end

if dealtCards[i].col==“black” then
blackCount=blackCount-1
end
dealtCards[i]:removeSelf()
dealtCards[i] = nil
dieChannel = audio.play( qs )
yard[i]=“B”
yardSize=yardSize-1
cardPointer=i-1

if poneTurn==true then poneScore=poneScore+2
thistot.text=poneScore
else ptwoScore=ptwoScore+2
lasttot.text=ptwoScore
end
else
end

elseif dealtCards[i]~=nil and dealtCards[i].rank==“face” then
local clumpNum=i
– so in here, there needs to be a quick pull of all face cards below that value. thought I had it in here elsewhere.
dealtCards[i].s=0
if dealtCards[i].ident==die.poz then dealtCards[i].s=dealtCards[i].s+die.value
end
if dealtCards[i].ident==die2.poz then dealtCards[i].s=dealtCards[i].s+die2.value
end
if dealtCards[i].ident==bdie.poz then dealtCards[i].s=dealtCards[i].s+bdie.value
end
if dealtCards[i].ident==bdie2.poz then dealtCards[i].s=dealtCards[i].s+bdie2.value
end
if dealtCards[i].ident==rdie.poz then dealtCards[i].s=dealtCards[i].s+rdie.value
end
if dealtCards[i].ident==rdie2.poz then dealtCards[i].s=dealtCards[i].s+rdie2.value
end
print (“face score is”…dealtCards[i].s)
if dealtCards[i].s>=12 then
if dealtCards[i].ident==die.poz then – DEBUG - transfer the muted above.
die.x = 20
die.y = 20
die.poz=0
die.locked=false
die.value=0
die.chosen=false
end

if dealtCards[i].ident==die2.poz then
die2.x = 55
die2.y = 55
die2.poz=0
die2.locked=false
die2.value=0
die2.chosen=false
end

if dealtCards[i].ident==bdie.poz then
bdie.x = 425
bdie.y = 55
bdie.poz=0
bdie.locked=false
bdie.value=0
bdie.chosen=false
end

if dealtCards[i].ident==bdie2.poz then
bdie2.x = 460
bdie2.y = 20
bdie2.poz=0
bdie2.locked=false
bdie2.value=0
bdie2.chosen=false
end

if dealtCards[i].ident==rdie.poz then
rdie.x = 55
rdie.y = 295
rdie.poz=0
rdie.locked=false
rdie.value=0
rdie.chosen=false
end

if dealtCards[i].ident==rdie2.poz then
rdie2.x = 20
rdie2.y = 260
rdie2.poz=0
rdie2.locked=false
rdie2.value=0
rdie2.chosen=false
end
acFace=dealtCards[i].ident
if dealtCards[i].col==“red” then
redCount=redCount-1
end

if dealtCards[i].col==“black” then
blackCount=blackCount-1
end
dealtCards[i]:removeSelf()
dealtCards[i] = nil
dieChannel = audio.play( qs )
print (“face card pos is”…i)
yard[i]=“B”
yardSize=yardSize-1
cardPointer=i-1

–x
for zv=1,8 do – this should just go through the 1st eight cards - really, what else is there…
–for i=1,cardPointer do – replace this with a more advanced variable
if dealtCards[zv]~=nil then
if dealtCards[zv].faceRank~=nil then
if dealtCards[zv]~=clumpNum and dealtCards[zv].rank==“face” then
if dealtCards[i].faceRank > dealtCards[zv].faceRank then

if dealtCards[zv].col==“red” then
redCount=redCount-1
end

if dealtCards[zv].col==“black” then
blackCount=blackCount-1
end

if poneTurn==true then poneScore=poneScore+5
thistot.text=poneScore
else ptwoScore=ptwoScore+5
lasttot.text=ptwoScore
end

dealtCards[zv]:removeSelf()
dealtCards[zv] = nil
dieChannel = audio.play( qs )
end
– this will be a loop from 1 through 8.
– it will ignore the currently active card… so this should be in the scoring loop.
– so if the card’s rank is face card and its table rank is higher
end
end
end
end

faceDown()

if poneTurn==true then poneScore=poneScore+5
thistot.text=poneScore
else ptwoScore=ptwoScore+5
lasttot.text=ptwoScore
end

else
–dealtCards[i].josco=0
end

---- END LAST
end – the if end
end – loop end
end

local function cleanout()
if die.currentFrame>6 then die.currentFrame=die.currentFrame-6 end
if die2.currentFrame>6 then die2.currentFrame=die2.currentFrame-6 end
if bdie.currentFrame>6 then bdie.currentFrame=bdie.currentFrame-6 end
if bdie2.currentFrame>6 then bdie2.currentFrame=bdie2.currentFrame-6 end
if rdie.currentFrame>6 then rdie.currentFrame=rdie.currentFrame-6 end
if rdie2.currentFrame>6 then rdie2.currentFrame=rdie2.currentFrame-6 end
end
local function lockdown(event)
cleanout()
if event.phase == “ended” and event.target.currentFrame~=2 then
if picked==true then
toLock=toLock+1
– print (“ChosenDice is”…chosenDice)
dieChannel = audio.play( slam )
lastTrgd=0
event.target.currentFrame=2
if chosenDie==1 and die.locked==false then
die.locked=true
die.inPool=2
die2.locked=true
–whitelock=true
die.currentFrame=die.currentFrame-6
end
if chosenDie==2 and die2.locked==false then
die2.locked=true
die2.inPool=2
die.locked=true
–whitelock=true
die2.currentFrame=die2.currentFrame-6
end
if chosenDie==3 and bdie.locked==false then bdie.locked=true
bdie.inPool=2
bdie.currentFrame=bdie.currentFrame-6
end
if chosenDie==4 and bdie2.locked==false then bdie2.locked=true
bdie2.currentFrame=bdie2.currentFrame-6
bdie2.inPool=2
end
if chosenDie==5 and rdie.locked==false then rdie.locked=true
rdie.currentFrame=rdie.currentFrame-6
rdie.inPool=2
end
if chosenDie==6 and rdie2.locked==false then rdie2.locked=true
rdie2.currentFrame=rdie2.currentFrame-6
rdie2.inPool=2
end
dieFrame.isVisible=false
chosenDie=0
picked=false
if toLock==2 then
scokeep()
btn_Deal.isVisible=true
end
end
end
end

_G.lok = sprite.newSprite( lockSet )
lok.x = 455
lok.y = 256
lok:prepare(“lok”)
localGroup:insert(lok)
lok:addEventListener( “touch”, lockdown )

_G.lok2 = sprite.newSprite( lockSet )
lok2.x = 405
lok2.y = 290
lok2:prepare(“lok2”)
localGroup:insert(lok2)
lok2:addEventListener( “touch”, lockdown )
btn_Deal:addEventListener ( “tap”, dealaCard )
return localGroup – return your group for director
end – end of ‘new’ function

M.new=new – must call new as an M function

return M
[/code] [import]uid: 144359 topic_id: 35861 reply_id: 335861[/import]

Hi @sumosalesman, please post a better description of your problem and some code there the problem might be located. There isn’t enough here to answer any question for you.

[import]uid: 199310 topic_id: 35861 reply_id: 142567[/import]

Hi @sumosalesman, please post a better description of your problem and some code there the problem might be located. There isn’t enough here to answer any question for you.

[import]uid: 199310 topic_id: 35861 reply_id: 142567[/import]