Looking for help or insight

Here I have a card game, BlackJack…When I press Play in the lower right corner, it doesent even go to the background… Can anyone take a peek and see whats wrong ? I see no error MSG’s…P.S. I’ve insereted 2 text() lines after the print() lines…

displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
    suit={??,??,??,??}
    value={" 2"," 3"," 4"," 5"," 6"," 7"," 8",
            " 9","10","J","Q","K","A"}  
    font("Georgia-BoldItalic")
    fontSize(30)
    textMode(CORNER)
    showKeyboard()
    output.clear()
    player,dealer={},{} 
    for z=1,2 do
    table.insert(player,math.random(11))
    table.insert(dealer,math.random(11))
    end   
    showPlayer(1)
end
function draw()
    background(0)
      fill(255)
--if answer is Stay, then
    if ans=="s" then 
        output.clear()
            showDealer()
               showPlayer(2)
                   showWinner()  
--if answer is Hit, then      
    elseif ans=="h" then 
        output.clear()
            table.insert(player,math.random(11))
                showPlayer(1)
--if answer is Play again, then
          elseif ans=="a" then
              setup()
    end 
    
      ans=""       
end
--================================
function showDealer()
    dealerSum=0
      for a=1,#dealer do
        dealerSum=dealerSum+dealer[a]
      end

     while dealerSum<17 do
        dealerSum=0
            table.insert(dealer,math.random(11))
              for a=1,#dealer do
                  dealerSum=dealerSum+dealer[a]
              end
      end



    --Print out to compiler
    print("The dealer has a total of "..dealerSum)
    print("from these cards "..table.concat(dealer," "))
    text("The dealer has a total of    "..dealerSum,100,HEIGHT-100)
    text("from these cards "..table.concat(dealer," "),100,HEIGHT-130)
end
--================================
function showPlayer(a)
    playerSum=0
      for a=1,#player do
        playerSum=playerSum+player[a]
      end
--Print out to compiler
    print("You have a total of  "..playerSum)
    print("From these Cards  "..table.concat(player," "))
    text("You have a total of    "..playerSum,100,HEIGHT-200)
    text("From these Cards    "..table.concat(player," "),100,HEIGHT-230)

  if playerSum>21 then
       showWinner()
           elseif a==1 then
--Print out to compiler
  print("\
\
Do you want to stay(s) or hit(h)")
  text("\
\
Do you want to stay(s) or hit(h)",100,HEIGHT-330)  
  end   
end

function showWinner()
    if playerSum>21 then
      print("Dealer wins!")
        text("Dealer wins!",100,HEIGHT-430)
    elseif dealerSum>21 then
      print("You win!")
        text("You win!",100,HEIGHT-430)
    elseif playerSum>dealerSum then
      print("You win!")
        text("You win!",100,HEIGHT-430)
      else
        print("Dealer wins!")
           text("Dealer wins!",100,HEIGHT-430)
      end -- end if loop
     print("Play again ?(a)")
     text("Play again ?(a)",100,HEIGHT-430)
end

function keyboard(k)
    ans=k
end

@kendog400 Why don’t you use the version I wrote for you that was converted to use text and go from there.

dave1707, I was trying to see & learn what makes this tick, if I get a good understanding I can start to make my own card games. I cant thank you enough for all the help you have given. Its easy to give up on Codea and through in the towel, and blame everyone else.

I have another one here…I press play and nothing happens, I can’t even get to the background, can you spot anything wrong ? P.S. added a text() function under the print() function…

-- print 5 cards to compiler
function setup()
s={"??","??","??","??"}      
v={"2","3","4","5","6","7","8","9","10","J","Q","K","A"}

function draw()
   Shuffled=shuffleCards(5)    
     card=0
       for x=1,10 do
         for y=1,5 do
           card=card+1
       s=math.ceil(Shuffled[card]/13)   
       v=Shuffled[card]%13+1                
print(value[v].." of "..suit[s])       
text(value[v].." of "..suit[s], WIDTH/2,HEIGHT/2)       
         end
       print() 
   end
end
 
function shuffleCards(x)
   local d1, d2, s, y, z = {}, {}
      for z=1,52 do
         d2[z]=z                                   
      end      
   for y=1,x do                         
       d1,d2=d2,{}--swap
         for z=1,52 do
           s=math.random(1,#d1)    
           table.insert(d2,d1[s])       
           table.remove(d1,s)         
          end
   end
   return d2                                       
end
function setup()
    suit={"??","??","??","??"}      
    value={"2","3","4","5","6","7","8","9","10","J","Q","K","A"}
    Shuffled=shuffleCards(5)    
end

function draw()
    background(223, 210, 149, 255)
    fill(255)
    card=0
    for x=1,10 do
        for y=1,5 do
            card=card+1
            s=math.ceil(Shuffled[card]/13)   
            v=Shuffled[card]%13+1                
            --print(value[v].." of "..suit[s])       
            text(value[v].." of "..suit[s], WIDTH/2,HEIGHT-card*20)       
        end
    end
end

function shuffleCards(x)
    local d1, d2, s, y, z = {}, {}
    for z=1,52 do
        d2[z]=z                                   
    end      
    for y=1,x do                         
        d1,d2=d2,{}--swap
        for z=1,52 do
            s=math.random(1,#d1)    
            table.insert(d2,d1[s])       
            table.remove(d1,s)         
        end
    end
    return d2                                       
end

Thanks !!

I have a new angle to learn Codea / Lua, it helps to have comments…

Is this an accurate decription of this line ?

  table.insert(deck,v[z%13+1]..s[z//13+1])  --insert a value & a suit ?

Does the % sign mean format ? What does the “//“ two slashes stand for ?

Can anyone explain this small Shuffle f(x) ?

function shuffle()
    for q=1,100 do                                               --Shuffle 100 times ?
        a,b=math.random(52),math.random(52).  —Pluck a card at random ?
        deck[a],deck[b]=deck[b],deck[a].               —Swap deck [a] for [b] ?
    end
end

@kendog400 The % doesn’t mean format even though it’s used for format. In this case the % means mod division which is the remainder after a divide. That is 23 % 10 is 2 with a remainder of 3. 23 % 10 = 3. The // is integer divide, the result is a whole number. 23 // 10 = 2 . As for the small shuffle, that takes a string of 52 numbers and swaps 2 random positions. It does that 100 times which would result in a random string of numbers. The % and // could have been answered by doing a google search. As for comments on the small shuffle, the first comment could be loop 100 times. The second comment could be get 2 random numbers from 1 To 52. The third comment could be swap the random deck positions with each other.

@kendog400 Here’s a link to the lua reference manual. I would suggest looking thru this, but don’t take it too literally since it doesn’t all apply to Codea. It should give you some answers you might have.

https://www.lua.org/manual/5.3/manual.html

OK…thanks

I looked through the Lua reference manual, the explanation isnt that clear…
Take a peek :
• __add: addition (+) operation.
• __sub: subtraction (-) operation.
• __mul: ……multiplication.(*).operation.
__div: division (/) operation.
• __mod: modulo (%) operation.
• __pow: exponentiation (^) operation.
• __unm: negation (unary -) operation.
• __idiv: floor division (//) operation.
• __band: bitwise AND (&) operation.
• __bor: bitwise OR (|) operation.
• __bxor: exclusive OR (~) operation.
• __bnot: NOT (~) operation
• __concat: concatenation (…) operation.
• __len: length (#) operation.
• __eq: equal (==) operation.
• __lt: less than (<) operation.
• __le: less equal (<=) operation.
• __index: indexing access table[key].
The shortcuts are in place, but the explanation ?
Is there such thing as a Lua codeing camp ?
A place where I could get some sort of classes ?
Something that could help me get my roll on ?

@kendog400 Those are used for metatables, something you probably won’t use for a long time if you use them at all. I haven’t used metatables and probably never will. As you look thru the reference, not everything is going to apply. Kind of just skim thru the reference so when you come across something you’re coding in Codea that you don’t understand, you might remember seeing it in the reference.

OK…