This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DMKxD's profile picture

My program dont gives an output

Started by DMKxD, 08 July 2012 - 06:34 PM
DMKxD #1
Posted 08 July 2012 - 08:34 PM
I just programed a BlackJack game, but it dont gives an output and i can't find the reason, thx for your help

playerscore1 = 0
playerscore2 = 0
player1scores = {}
player2scores = {}
player1cards = {}
player2cards = {}
weiter = false
endeplayer1 = false
endeplayer2 = false
random = 0
weristdran = 1
zahltimer = 1
test = ""
running = false
go = true
stop = false
player1verloren = false
player2verloren = false
function dummy1(a)
if player1cards[0] == nil then
	player1cards[0] = a
elseif player1cards[1] == nil then
		player1cards[1] = a
elseif player1cards[2] == nil then
		player1cards[2] = a

elseif player1cards[3] == nil then
		player1cards[3] = a

elseif player1cards[4] == nil then
		player1cards[4] = a

elseif player1cards[5] == nil then
		player1cards[5] = a

elseif player1cards[6] == nil then
		player1cards[6] = a

elseif player1cards[7] == nil then
		player1cards[7] = a
end
end
function dummy2(:)/>/>
if player2cards[0] == nil then
	player2cards[0] = b
elseif player2cards[1] == nil then
		player2cards[1] = b
elseif player2cards[2] == nil then
		player2cards[2] = b

elseif player2cards[3] == nil then
		player2cards[3] = b

elseif player2cards[4] == nil then
		player2cards[4] = b

elseif player2cards[5] == nil then
		player2cards[5] = b

elseif player2cards[6] == nil then
		player2cards[6] = b

elseif player2cards[7] == nil then
		player2cards[7] = b
end
end
function scores1(c)
if player1scores[0] == nil then
	player1scores[0] = c
elseif player1scores[1] == nil then
		player1scores[1] = c
elseif player1scores[2] == nil then
		player1scores[2] = c

elseif player1scores[3] == nil then
		player1scores[3] = c

elseif player1scores[4] == nil then
		player1scores[4] = c

elseif player1scores[5] == nil then
		player1scores[5] = c

elseif player1scores[6] == nil then
		player1scores[6] = c

elseif player1scores[7] == nil then
		player1scores[7] = c
end
playerscore1 = player1scores[1] + player1scores[2] + player1scores[3] + player1scores[4] + player1scores[5] + player1scores[6] + player1scores[7]
end
function scores2(d)
if player2scores[0] == nil then
	player2scores[0] = d
elseif player2scores[1] == nil then
		player2scores[1] = d
elseif player2scores[2] == nil then
		player2scores[2] = d

elseif player2scores[3] == nil then
		player2scores[3] = d

elseif player2scores[4] == nil then
		player2scores[4] = d

elseif player2scores[5] == nil then
		player2scores[5] = d

elseif player2scores[6] == nil then
		player2scores[6] = d

elseif player2scores[7] == nil then
		player2scores[7] = d
end
playerscore2 = player2scores[1] + player2scores[2] + player2scores[3] + player2scores[4] + player2scores[5] + player2scores[6] + player2scores[7]
end
function kartenziehen1()
random = math.random(56) + 1
if random >= 1 and random <= 4 then
  dummy1(2)
  scores1(2)
	elseif random >= 5 and random <= 8 then
	 dummy1(3)
	 scores1(3)
	elseif random >= 9 and random <= 12 then
	 dummy1(4)
	 scores1(4)
	elseif random >= 13 and random <= 16 then
	 dummy1(5)
	 scores1(5)
	elseif random >= 17 and random <= 20 then
	 dummy1(6)
	 scores1(6)
	elseif random >= 21 and random <= 24 then
		dummy1(7)
		scores1(7)
	elseif random >= 25 and random <= 28 then
		dummy1(8)
		scores1(8)
	elseif random >= 29 and random <= 32 then
		dummy1(9)
		scores1(9)
	elseif random >= 33 and random <= 36 then
		dummy1(10)
		scores1(10)
	elseif random >= 37 and random <= 40 then
		dummy1(B)/>/>
		scores1(10)
	elseif random >= 41 and random <= 44 then
		dummy1(D)
		scores1(10)
	elseif random >= 45 and random <= 48 then
		dummy1(K)
		scores1(10)
	elseif random >= 49 and random <= 52 then
		dummy1(J)
		scores1(10)
	elseif random >= 53 and random <= 56 then
		dummy1(A)
		scores1(11)
	end
end
function kartenziehen2()
	sleep(2)
random = math.random(56) + 1
if random >= 1 and random <= 4 then
  dummy1(2)
  scores1(2)
	elseif random >= 5 and random <= 8 then
	 dummy1(3)
	 scores1(3)
	elseif random >= 9 and random <= 12 then
	 dummy1(4)
	 scores1(4)
	elseif random >= 13 and random <= 16 then
	 dummy1(5)
	 scores1(5)
	elseif random >= 17 and random <= 20 then
	 dummy1(6)
	 scores1(6)
	elseif random >= 21 and random <= 24 then
		dummy1(7)
		scores1(7)
	elseif random >= 25 and random <= 28 then
		dummy1(8)
		scores1(8)
	elseif random >= 29 and random <= 32 then
		dummy1(9)
		scores1(9)
	elseif random >= 33 and random <= 36 then
		dummy1(10)
		scores1(10)
	elseif random >= 37 and random <= 40 then
		dummy1(B)/>/>
		scores1(10)
	elseif random >= 41 and random <= 44 then
		dummy1(D)
		scores1(10)
	elseif random >= 45 and random <= 48 then
		dummy1(K)
		scores1(10)
	elseif random >= 49 and random <= 52 then
		dummy1(J)
		scores1(10)
	elseif random >= 53 and random <= 56 then
		dummy1(A)
		scores1(11)
end
end
function Wechseln()
while weiter == true or weiter == false do
  if go == true then
   go = false
   stop = true
break end
  if go == false then
   go = true
   stop = false
break end
end
end
function yesno()
repeat
local e, key = os.pullEvent( "key" )
if key == 203 or key == 205 then
  Wechseln()
	 term.clearLine()
	end
	if go == true then
	 print("Go")
	elseif stop == true then
	 print("Stop")
	end
until key == 28
function scoreboard()
print("BlackJack v1.0 by DMKxD")
print("*********************************")
print("Player  Bot")
print(player1cards[0].. "   " ..player2cards[0])
print(player1cards[1].. "   " ..player2cards[1])
print(player1cards[2].. "   " ..player2cards[2])
print(player1cards[3].. "   " ..player2cards[3])
print(player1cards[4].. "   " ..player2cards[4])
print(player1cards[5].. "   " ..player2cards[5])
print(player1cards[6].. "   " ..player2cards[6])
print(player1cards[7].. "   " ..player2cards[7])
	print("")
print("Score Player: " ..playerscore1.."	Score Bank: " ..playerscore2)
end
repeat
shell.run("clear")
kartenziehen1()
scoreboard()
write("Continue?")
yesno()
if stop == true then
if playerscore1 > 21 then
  print("You loose...")
  sleep(3)
  shell.run("reboot")
else
print("Your score is saved, now let's see if you could beat the bank!")
weristdran = 2
end
end
until weristdran == 2
repeat
shell.run("clear")
kartenziehen2()
scoreboard()
if playerscore2 > 16 then
if playerscore2 > 21 then
  player2verloren = true
end
weristdran = 3
end
until weristran == 3
repeat
if playerscore1 > playerscore2 then
  print("You won!")
elseif playerscore1 == playerscore2 then
  print("Draw!")
end
sleep(4)
shell.run("reboot")
until weristdran == 4
end

cya DMKxD
BigSHinyToys #2
Posted 08 July 2012 - 09:06 PM
you define a lot of functions But you never call any of them.
call witch ever function you want to run first at the bottom of your script.
eg


-- other code above this
  player2verloren = true
end
weristdran = 3
end
until weristran == 3
repeat
if playerscore1 > playerscore2 then
  print("You won!")
elseif playerscore1 == playerscore2 then
  print("Draw!")
end
sleep(4)
shell.run("reboot")
until weristdran == 4
end
yesno()
this calls the function
DMKxD #3
Posted 08 July 2012 - 09:26 PM
I changed it to

playerscore1 = 0
playerscore2 = 0
player1scores = {}
player2scores = {}
player1cards = {}
player2cards = {}
weiter = false
endeplayer1 = false
endeplayer2 = false
random = 0
weristdran = 1
zahltimer = 1
test = ""
running = false
go = true
stop = false
player1verloren = false
player2verloren = false
function dummy1(a)
if player1cards[0] == nil then
	player1cards[0] = a
elseif player1cards[1] == nil then
		player1cards[1] = a
elseif player1cards[2] == nil then
		player1cards[2] = a

elseif player1cards[3] == nil then
		player1cards[3] = a

elseif player1cards[4] == nil then
		player1cards[4] = a

elseif player1cards[5] == nil then
		player1cards[5] = a

elseif player1cards[6] == nil then
		player1cards[6] = a

elseif player1cards[7] == nil then
		player1cards[7] = a
end
end
function dummy2(:)/>/>
if player2cards[0] == nil then
	player2cards[0] = b
elseif player2cards[1] == nil then
		player2cards[1] = b
elseif player2cards[2] == nil then
		player2cards[2] = b

elseif player2cards[3] == nil then
		player2cards[3] = b

elseif player2cards[4] == nil then
		player2cards[4] = b

elseif player2cards[5] == nil then
		player2cards[5] = b

elseif player2cards[6] == nil then
		player2cards[6] = b

elseif player2cards[7] == nil then
		player2cards[7] = b
end
end
function scores1(c)
if player1scores[0] == nil then
	player1scores[0] = c
elseif player1scores[1] == nil then
		player1scores[1] = c
elseif player1scores[2] == nil then
		player1scores[2] = c

elseif player1scores[3] == nil then
		player1scores[3] = c

elseif player1scores[4] == nil then
		player1scores[4] = c

elseif player1scores[5] == nil then
		player1scores[5] = c

elseif player1scores[6] == nil then
		player1scores[6] = c

elseif player1scores[7] == nil then
		player1scores[7] = c
end
playerscore1 = player1scores[1] + player1scores[2] + player1scores[3] + player1scores[4] + player1scores[5] + player1scores[6] + player1scores[7]
end
function scores2(d)
if player2scores[0] == nil then
	player2scores[0] = d
elseif player2scores[1] == nil then
		player2scores[1] = d
elseif player2scores[2] == nil then
		player2scores[2] = d

elseif player2scores[3] == nil then
		player2scores[3] = d

elseif player2scores[4] == nil then
		player2scores[4] = d

elseif player2scores[5] == nil then
		player2scores[5] = d

elseif player2scores[6] == nil then
		player2scores[6] = d

elseif player2scores[7] == nil then
		player2scores[7] = d
end
playerscore2 = player2scores[1] + player2scores[2] + player2scores[3] + player2scores[4] + player2scores[5] + player2scores[6] + player2scores[7]
end
function kartenziehen1()
random = math.random(56) + 1
if random >= 1 and random <= 4 then
  dummy1(2)
  scores1(2)
	elseif random >= 5 and random <= 8 then
	 dummy1(3)
	 scores1(3)
	elseif random >= 9 and random <= 12 then
	 dummy1(4)
	 scores1(4)
	elseif random >= 13 and random <= 16 then
	 dummy1(5)
	 scores1(5)
	elseif random >= 17 and random <= 20 then
	 dummy1(6)
	 scores1(6)
	elseif random >= 21 and random <= 24 then
		dummy1(7)
		scores1(7)
	elseif random >= 25 and random <= 28 then
		dummy1(8)
		scores1(8)
	elseif random >= 29 and random <= 32 then
		dummy1(9)
		scores1(9)
	elseif random >= 33 and random <= 36 then
		dummy1(10)
		scores1(10)
	elseif random >= 37 and random <= 40 then
		dummy1(B)/>/>
		scores1(10)
	elseif random >= 41 and random <= 44 then
		dummy1(D)
		scores1(10)
	elseif random >= 45 and random <= 48 then
		dummy1(K)
		scores1(10)
	elseif random >= 49 and random <= 52 then
		dummy1(J)
		scores1(10)
	elseif random >= 53 and random <= 56 then
		dummy1(A)
		scores1(11)
	end
end
function kartenziehen2()
	sleep(2)
random = math.random(56) + 1
if random >= 1 and random <= 4 then
  dummy1(2)
  scores1(2)
	elseif random >= 5 and random <= 8 then
	 dummy1(3)
	 scores1(3)
	elseif random >= 9 and random <= 12 then
	 dummy1(4)
	 scores1(4)
	elseif random >= 13 and random <= 16 then
	 dummy1(5)
	 scores1(5)
	elseif random >= 17 and random <= 20 then
	 dummy1(6)
	 scores1(6)
	elseif random >= 21 and random <= 24 then
		dummy1(7)
		scores1(7)
	elseif random >= 25 and random <= 28 then
		dummy1(8)
		scores1(8)
	elseif random >= 29 and random <= 32 then
		dummy1(9)
		scores1(9)
	elseif random >= 33 and random <= 36 then
		dummy1(10)
		scores1(10)
	elseif random >= 37 and random <= 40 then
		dummy1(B)/>/>
		scores1(10)
	elseif random >= 41 and random <= 44 then
		dummy1(D)
		scores1(10)
	elseif random >= 45 and random <= 48 then
		dummy1(K)
		scores1(10)
	elseif random >= 49 and random <= 52 then
		dummy1(J)
		scores1(10)
	elseif random >= 53 and random <= 56 then
		dummy1(A)
		scores1(11)
end
end
function Wechseln()
while weiter == true or weiter == false do
  if go == true then
   go = false
   stop = true
break end
  if go == false then
   go = true
   stop = false
break end
end
end
function yesno()
repeat
local e, key = os.pullEvent( "key" )
if key == 203 or key == 205 then
  Wechseln()
	 term.clearLine()
	end
	if go == true then
	 print("Go")
	elseif stop == true then
	 print("Stop")
	end
until key == 28
function scoreboard()
print("BlackJack v1.0 by DMKxD")
print("*********************************")
print("Player  Bot")
print(player1cards[0].. "   " ..player2cards[0])
print(player1cards[1].. "   " ..player2cards[1])
print(player1cards[2].. "   " ..player2cards[2])
print(player1cards[3].. "   " ..player2cards[3])
print(player1cards[4].. "   " ..player2cards[4])
print(player1cards[5].. "   " ..player2cards[5])
print(player1cards[6].. "   " ..player2cards[6])
print(player1cards[7].. "   " ..player2cards[7])
	print("")
print("Score Player: " ..playerscore1.."	Score Bank: " ..playerscore2)
end
repeat
shell.run("clear")
kartenziehen1()
scoreboard()
write("Continue?")
yesno()
if stop == true then
if playerscore1 > 21 then
  print("You loose...")
  sleep(3)
  shell.run("reboot")
else
print("Your score is saved, now let's see if you could beat the bank!")
weristdran = 2
end
end
until weristdran > 0 and weristdran < 2
repeat
shell.run("clear")
kartenziehen2()
scoreboard()
if playerscore2 > 16 then
if playerscore2 > 21 then
  player2verloren = true
end
weristdran = 3
end
until eristdran > 1 and weristdran < 3
repeat
if playerscore1 > playerscore2 then
  print("You won!")
elseif playerscore1 == playerscore2 then
  print("Draw!")
end
sleep(4)
shell.run("reboot")
until eristdran > 4
end
yesno()
but now the output is "Go" or "Stop" and not
print("BlackJack v1.0 by DMKxD")
print("*********************************")
print("Player Bot")
print(player1cards[0].. " " ..player2cards[0])
print(player1cards[1].. " " ..player2cards[1])
print(player1cards[2].. " " ..player2cards[2])
print(player1cards[3].. " " ..player2cards[3])
print(player1cards[4].. " " ..player2cards[4])
print(player1cards[5].. " " ..player2cards[5])
print(player1cards[6].. " " ..player2cards[6])
print(player1cards[7].. " " ..player2cards[7])
print("")
print("Score Player: " ..playerscore1.." Score Bank: " ..playerscore2)
DMKxD #4
Posted 08 July 2012 - 09:36 PM
Btw. the output should look like

BlackJack v1.0 by DMKxD
*********************************
Player Bot
3 2
A






Score Player: 14 Score Bank: 2

Continue? Go/Stop

cya
DMKxD
BigSHinyToys #5
Posted 09 July 2012 - 12:43 AM
you never call a lot of your code. you need to go through it following the flow of the program.

currently you call yesno()
yesno() calls Wechseln()
Wechseln() calls no other function.

you need to make Wechseln() or one of the above function call the function's you want to run.

I am having trouble understanding how your code is supposed to work making it almost impossible for me to fix it. if you could explain better what you want each function to do and when I might be able to fix .

just remember a computer only does what you tell it to. It wont run a function that has not been called specifically in its code.
DMKxD #6
Posted 11 July 2012 - 04:45 PM
I've changed some things:

playerscore1 = 0
playerscore2 = 0
player1scores0 = 0
player1scores1 = 0
player1scores2 = 0
player1scores3 = 0
player1scores4 = 0
player1scores5 = 0
player1scores6 = 0
player1scores7 = 0
player2scores0 = 0
player2scores1 = 0
player2scores2 = 0
player2scores3 = 0
player2scores4 = 0
player2scores5 = 0
player2scores6 = 0
player2scores7 = 0
player1cards0 = ""
player1cards1 = ""
player1cards2 = ""
player1cards3 = ""
player1cards4 = ""
player1cards5 = ""
player1cards6 = ""
player1cards7 = ""
player1cards8 = ""
player2cards0 = ""
player2cards1 = ""
player2cards2 = ""
player2cards3 = ""
player2cards4 = ""
player2cards5 = ""
player2cards6 = ""
player2cards7 = ""
weiter = true
endeplayer1 = false
endeplayer2 = false
random = 0
weristdran = 1
zahltimer = 1
test = ""
running = false
go = false
stop = true
player1verloren = false
player2verloren = false
function dummy1(a) -- Translate the number a string for the scoreboard (Interface)
if player1cards0 == "" then
	player1cards0 = a
elseif player1cards1 == "" then
		player1cards1 = a
elseif player1cards2 == "" then
		player1cards2 = a

elseif player1cards3 == "" then
		player1cards3 = a

elseif player1cards4 == "" then
		player1cards4 = a

elseif player1cards5 == "" then
		player1cards5 = a
	  
elseif player1cards6 == "" then
		player1cards6 = a

elseif player1cards7 == "" then
		player1cards7 = a
end
end
function dummy2(B)/>/> -- Translate the number a string for the scoreboard (Interface)
if player2cards0 == "" then
	player2cards0 = b
elseif player2cards1 == "" then
		player2cards1 = b
elseif player2cards2 == "" then
		player2cards2 = b

elseif player2cards3 == "" then
		player2cards3 = b

elseif player2cards4 == "" then
		player2cards4 = b

elseif player2cards5 == "" then
		player2cards5 = b
	  
elseif player2cards6 == "" then
		player2cards6 = b

elseif player2cards7 == "" then
		player2cards7 = b
end
end
function scores1(c) -- Translate the number into a score
if player1scores0 == 0 then
	player1scores0 = c
elseif player1scores1 == 0 then
		player1scores1 = c
elseif player1scores2 == 0 then
		player1scores2 = c

elseif player1scores3 == 0 then
		player1scores3 = c

elseif player1scores4 == 0 then
		player1scores4 = c

elseif player1scores5 == 0 then
		player1scores5 = c

elseif player1scores6 == 0 then
		player1scores6 = c

elseif player1scores7 == 0 then
		player1scores7 = c
end
playerscore1 = player1scores0 + player1scores1 + player1scores2 + player1scores3 + player1scores4 + player1scores5 + player1scores6 + player1scores7
end
function scores2(d) -- Translate the number into a score
if player2scores0 == 0 then
	player2scores0 = d
elseif player2scores1 == 0 then
		player2scores1 = d
elseif player2scores2 == 0 then
		player2scores2 = d

elseif player2scores3 == 0 then
		player2scores3 = d

elseif player2scores4 == 0 then
		player2scores4 = d

elseif player2scores5 == 0 then
		player2scores5 = d

elseif player2scores6 == 0 then
		player2scores6 = d

elseif player2scores7 == 0 then
		player2scores7 = d
end
playerscore2 = player2scores0 + player2scores1 + player2scores2 + player2scores3 + player2scores4 + player2scores5 + player2scores6 + player2scores7
end
function kartenziehen1() -- Create a random Card for Player2
random = math.random(56) + 1
if random >= 1 and random <= 4 then
  dummy1(2)
  scores1(2)
	elseif random >= 5 and random <= 8 then
	 dummy1(3)
	 scores1(3)
	elseif random >= 9 and random <= 12 then
	 dummy1(4)
	 scores1(4)
	elseif random >= 13 and random <= 16 then
	 dummy1(5)
	 scores1(5)
	elseif random >= 17 and random <= 20 then
	 dummy1(6)
	 scores1(6)
	elseif random >= 21 and random <= 24 then
		dummy1(7)
		scores1(7)
	elseif random >= 25 and random <= 28 then
		dummy1(8)
		scores1(8)
	elseif random >= 29 and random <= 32 then
		dummy1(9)
		scores1(9)
	elseif random >= 33 and random <= 36 then
		dummy1(10)
		scores1(10)
	elseif random >= 37 and random <= 40 then
		dummy1(B)/>/>
		scores1(10)
	elseif random >= 41 and random <= 44 then
		dummy1(D)
		scores1(10)
	elseif random >= 45 and random <= 48 then
		dummy1(K)
		scores1(10)
	elseif random >= 49 and random <= 52 then
		dummy1(J)
		scores1(10)
	elseif random >= 53 and random <= 56 then
		dummy1(A)
		scores1(11)
	end
end
function kartenziehen2() -- Create a random Card for Player2 (Bot)
	sleep(2)
random = math.random(56) + 1
if random >= 1 and random <= 4 then
  dummy1(2)
  scores1(2)
	elseif random >= 5 and random <= 8 then
	 dummy1(3)
	 scores1(3)
	elseif random >= 9 and random <= 12 then
	 dummy1(4)
	 scores1(4)
	elseif random >= 13 and random <= 16 then
	 dummy1(5)
	 scores1(5)
	elseif random >= 17 and random <= 20 then
	 dummy1(6)
	 scores1(6)
	elseif random >= 21 and random <= 24 then
		dummy1(7)
		scores1(7)
	elseif random >= 25 and random <= 28 then
		dummy1(8)
		scores1(8)
	elseif random >= 29 and random <= 32 then
		dummy1(9)
		scores1(9)
	elseif random >= 33 and random <= 36 then
		dummy1(10)
		scores1(10)
	elseif random >= 37 and random <= 40 then
		dummy1(B)/>/>
		scores1(10)
	elseif random >= 41 and random <= 44 then
		dummy1(D)
		scores1(10)
	elseif random >= 45 and random <= 48 then
		dummy1(K)
		scores1(10)
	elseif random >= 49 and random <= 52 then
		dummy1(J)
		scores1(10)
	elseif random >= 53 and random <= 56 then
		dummy1(A)
		scores1(11)
end
end
function Wechseln() -- Change between go == true / false and stop == true / false (Don't work correctly :/)
while weiter == true or weiter == false do
  if go == true then
   go = false
   stop = true
break end
  if go == false then
   go = true
   stop = false
break end
end
end
function yesno() --Change between Stop and Go (Don't work correctly :/)
repeat
local e, key = os.pullEvent( "key" )
if key == 203 or key == 205 then
  Wechseln()
	end
	if go == true then
	 print("Go")
	elseif stop == true then
	 print("Stop")
	end
until key == 28
function scoreboard() -- Interface
print("BlackJack v1.0 by DMKxD")
print("*********************************")
print("Player  Bot")
print(player1cards0.. "	" ..player2cards0)
print(player1cards1.. "	" ..player2cards1)
print(player1cards2.. "	" ..player2cards2)
print(player1cards3.. "	" ..player2cards3)
print(player1cards4.. "	" ..player2cards4)
print(player1cards5.. "	" ..player2cards5)
print(player1cards6.. "	" ..player2cards6)
print(player1cards7.. "	" ..player2cards7)
	print("")
print("Score Player: " ..playerscore1.."	Score Bank: " ..playerscore2)
end
repeat
shell.run("clear")
kartenziehen1()
scoreboard()
write("Continue? ")
yesno()
if stop == true then
if playerscore1 > 21 then
  print("You loose...")
  sleep(3)
  shell.run("reboot")
else
print("Your score is saved, now let's see if you could beat the bank!")
weristdran = 2
end
end
until weristdran > 2
repeat
shell.run("clear")
kartenziehen2()
scoreboard()
if playerscore2 > 16 then
if playerscore2 > 21 then
  player2verloren = true
end
weristdran = 3
end
until weristdran < 1 and weristdran > 3
repeat
if playerscore1 > playerscore2 then
  print("You won!")
elseif playerscore1 == playerscore2 then
  print("Draw!")
end
sleep(4)
shell.run("reboot")
until weristdran < 2 and weristdran > 4
end

The program should run like this:

First the player gets a random card automatically, then it shows the scoreboard and under the scoreboard will be shown "Continue?" and you could choose between Stop/Go. this is here: (The goal for the player is to get as close as he could to 21 points, if his points are bigger than 21 the output is "You loose…." and the computer will reboot.)

repeat
shell.run("clear")
kartenziehen1()
scoreboard()
write("Continue? ")
yesno()
if stop == true then
if playerscore1 > 21 then
  print("You loose...")
  sleep(3)
  shell.run("reboot")
else
print("Your score is saved, now let's see if you could beat the bank!")
weristdran = 2
end
end
until weristdran > 2
After the player have 21 points or the player choose "Stop", weristdran (Who is it) will be set to 2 (Bot). The Bot do nearly the same like the player, but with a little variation, cause the bot is allowed to take a card as long his points are smaller than 16 or 16. If his points are bigger than 16 he've to stop. This is shown here:

repeat
shell.run("clear")
kartenziehen2()
scoreboard()
if playerscore2 > 16 then
if playerscore2 > 21 then
  player2verloren = true
end
weristdran = 3
end
until weristdran < 1 and weristdran > 3
Now we come to the last part, The player has won if his score is bigger than the score of Player 2 or its a draw if its the same like Player 2.

repeat
if playerscore1 > playerscore2 then
  print("You won!")
elseif playerscore1 == playerscore2 then
  print("Draw!")
end
sleep(4)
shell.run("reboot")
until weristdran < 2 and weristdran > 4
end
Sry for my bad english i'm german :)/>/>
LucasUK #7
Posted 11 July 2012 - 06:52 PM
I havent read the code throughly anddont understand the variable names :)/>/> but my GUI is usually correct. (Notepad ++)

When I collapse all functions, to see what the program itself does I get:


playerscore1 = 0
playerscore2 = 0
player1scores0 = 0
player1scores1 = 0
player1scores2 = 0
player1scores3 = 0
player1scores4 = 0
player1scores5 = 0
player1scores6 = 0
player1scores7 = 0
player2scores0 = 0
player2scores1 = 0
player2scores2 = 0
player2scores3 = 0
player2scores4 = 0
player2scores5 = 0
player2scores6 = 0
player2scores7 = 0
player1cards0 = ""
player1cards1 = ""
player1cards2 = ""
player1cards3 = ""
player1cards4 = ""
player1cards5 = ""
player1cards6 = ""
player1cards7 = ""
player1cards8 = ""
player2cards0 = ""
player2cards1 = ""
player2cards2 = ""
player2cards3 = ""
player2cards4 = ""
player2cards5 = ""
player2cards6 = ""
player2cards7 = ""
weiter = true
endeplayer1 = false
endeplayer2 = false
random = 0
weristdran = 1
zahltimer = 1
test = ""
running = false
go = false
stop = true
player1verloren = false
player2verloren = false


And then the rest is functions. The loop code you quoted as: "First the player gets a random card automatically" is saved within the yesno function, which the main program never calls. Function scoreboard is also within the yesno function. End that function.
DMKxD #8
Posted 12 July 2012 - 01:35 PM
I've corrected some bugs but now i get some problems with the scoreboard

playerscore1 = 0
playerscore2 = 0
player1scores0 = 0
player1scores1 = 0
player1scores2 = 0
player1scores3 = 0
player1scores4 = 0
player1scores5 = 0
player1scores6 = 0
player1scores7 = 0
player2scores0 = 0
player2scores1 = 0
player2scores2 = 0
player2scores3 = 0
player2scores4 = 0
player2scores5 = 0
player2scores6 = 0
player2scores7 = 0
player1cards0 = "_"
player1cards1 = "_"
player1cards2 = "_"
player1cards3 = "_"
player1cards4 = "_"
player1cards5 = "_"
player1cards6 = "_"
player1cards7 = "_"
player1cards8 = "_"
player2cards0 = "_"
player2cards1 = "_"
player2cards2 = "_"
player2cards3 = "_"
player2cards4 = "_"
player2cards5 = "_"
player2cards6 = "_"
player2cards7 = "_"
weiter = true
endeplayer1 = false
endeplayer2 = false
random = 0
weristdran = 1
zahltimer = 1
test = ""
running = false
go = false
stop = true
player1verloren = false
player2verloren = false
function dummy1(a) --Translate the number a string for the scoreboard (Interface)
if player1cards0 == "_" then
	 player1cards0 = a
  elseif player1cards1 == "_" then
		player1cards1 = a
elseif player1cards2 == "_" then
		player1cards2 = a

   elseif player1cards3 == "_" then
		player1cards3 = a

elseif player1cards4 == "_" then
		player1cards4 = a

elseif player1cards5 == "_" then
		player1cards5 = a
	  
elseif player1cards6 == "_" then
		player1cards6 = a

elseif player1cards7 == "_" then
  player1cards7 = a
  end
end
function dummy2(B)/>/> --Translate the number a string for the scoreboard (Interface)
if player2cards0 == "_" then
	 player2cards0 = b
elseif player2cards1 == "_" then
		player2cards1 = b
elseif player2cards2 == "_" then
		player2cards2 = b

elseif player2cards3 == "_" then
		player2cards3 = b

elseif player2cards4 == "_" then
		player2cards4 = b

elseif player2cards5 == "_" then
  player2cards5 = b
	  
elseif player2cards6 == "_" then
		player2cards6 = b

elseif player2cards7 == "_" then
		player2cards7 = b
end
end
function scores1(c) --Translate the number into a score
if player1scores0 == 0 then
	 player1scores0 = c
elseif player1scores1 == 0 then
		player1scores1 = c
elseif player1scores2 == 0 then
		player1scores2 = c

elseif player1scores3 == 0 then
		player1scores3 = c

elseif player1scores4 == 0 then
		player1scores4 = c

elseif player1scores5 == 0 then
		player1scores5 = c

elseif player1scores6 == 0 then
  player1scores6 = c

elseif player1scores7 == 0 then
		player1scores7 = c
	end
playerscore1 = player1scores0 + player1scores1 + player1scores2 + player1scores3 + player1scores4 + player1scores5 + player1scores6 + player1scores7
end
function scores2(d) --Translate the number into a score
if player2scores0 == 0 then
	 player2scores0 = d
elseif player2scores1 == 0 then
		player2scores1 = d
elseif player2scores2 == 0 then
		player2scores2 = d

elseif player2scores3 == 0 then
		player2scores3 = d

elseif player2scores4 == 0 then
		player2scores4 = d

elseif player2scores5 == 0 then
		player2scores5 = d

elseif player2scores6 == 0 then
		player2scores6 = d

elseif player2scores7 == 0 then
		player2scores7 = d
end
playerscore2 = player2scores0 + player2scores1 + player2scores2 + player2scores3 + player2scores4 + player2scores5 + player2scores6 + player2scores7
end
function kartenziehen1() --Create a random Card for Player2
random = math.random(56) + 1
if random == 0 then
  random = math.random(56) + 1
elseif random == 0 then
  random = math.random(56) + 1
elseif random >= 1 and random <= 4 then
  dummy1(2)
  scores1(2)
	elseif random >= 5 and random <= 8 then
	 dummy1(3)
	 scores1(3)
	elseif random >= 9 and random <= 12 then
	 dummy1(4)
	 scores1(4)
	elseif random >= 13 and random <= 16 then
	 dummy1(5)
	 scores1(5)
	elseif random >= 17 and random <= 20 then
	 dummy1(6)
	 scores1(6)
	elseif random >= 21 and random <= 24 then
		dummy1(7)
		scores1(7)
	elseif random >= 25 and random <= 28 then
		dummy1(8)
		scores1(8)
	elseif random >= 29 and random <= 32 then
		dummy1(9)
		scores1(9)
	elseif random >= 33 and random <= 36 then
		dummy1(10)
		scores1(10)
	elseif random >= 37 and random <= 40 then
		dummy1(B)/>/>
		scores1(10)
	elseif random >= 41 and random <= 44 then
		dummy1(D)
		scores1(10)
	elseif random >= 45 and random <= 48 then
		dummy1(K)
		scores1(10)
	elseif random >= 49 and random <= 52 then
		dummy1(J)
		scores1(10)
	elseif random >= 53 and random <= 56 then
		dummy1(A)
		scores1(11)
	end
end
function kartenziehen2() --Create a random Card for Player2 (Bot)
	sleep(2)
random = math.random(56) + 1
if random == 0 then
  random = math.random(56) + 1
elseif random == 0 then
  random = math.random(56) + 1
elseif random >= 1 and random <= 4 then
  dummy1(2)
  scores1(2)
	elseif random >= 5 and random <= 8 then
	 dummy1(3)
	 scores1(3)
	elseif random >= 9 and random <= 12 then
	 dummy1(4)
	 scores1(4)
	elseif random >= 13 and random <= 16 then
	 dummy1(5)
	 scores1(5)
	elseif random >= 17 and random <= 20 then
	 dummy1(6)
	 scores1(6)
	elseif random >= 21 and random <= 24 then
		dummy1(7)
		scores1(7)
	elseif random >= 25 and random <= 28 then
		dummy1(8)
		scores1(8)
	elseif random >= 29 and random <= 32 then
		dummy1(9)
		scores1(9)
	elseif random >= 33 and random <= 36 then
		dummy1(10)
		scores1(10)
	elseif random >= 37 and random <= 40 then
		dummy1(B)/>/>
		scores1(10)
	elseif random >= 41 and random <= 44 then
		dummy1(D)
		scores1(10)
	elseif random >= 45 and random <= 48 then
		dummy1(K)
		scores1(10)
	elseif random >= 49 and random <= 52 then
		dummy1(J)
		scores1(10)
	elseif random >= 53 and random <= 56 then
		dummy1(A)
		scores1(11)
end
end
function Wechseln() --Change between go == true / false and stop == true / false (Don't work correctly :/)
while weiter == true do
  if go == true then
   go = false
   stop = true
   weiter = false
break end
  if go == false then
   go = true
   stop = false
   weiter = false
break end
end
end
function yesno() --Change between Stop and Go (Don't work correctly :/)
repeat
  local e, key = os.pullEvent( "key" )
  if key == 203 or key == 205 then
   weiter = true
   Wechseln()
	 end
	 if go == true then
	  print("Go")
	  print(go)
	 elseif stop == true then
	  print("Stop")
	  print(stop)
	 end
until key == 28
ende1()
end
function ende1()
if stop == true then
   if playerscore1 > 21 then
	print("You loose...")
	 sleep(3)
	shell.run("reboot")
  else
   print("Your score is saved, now let's see if you could beat the bank!")
   weristdran = 2
  end
end
end
function ende2()
if playerscore2 > 16 then
  if playerscore2 > 21 then
   player2verloren = true
  end
weristdran = 3
end
end
function ende3()
if playerscore1 > playerscore2 or player2erloren == true then
   print("You won!")
elseif playerscore1 == playerscore2 then
	print("Draw!")
end
sleep(4)
shell.run("reboot")
end
function scoreboard() --Interface
print("BlackJack v1.0 by DMKxD")
print("*********************************")
print("Player  Bot")
print(player1cards0.. "	" ..player2cards0)
print(player1cards1.. "	" ..player2cards1)
print(player1cards2.. "	" ..player2cards2)
print(player1cards3.. "	" ..player2cards3)
print(player1cards4.. "	" ..player2cards4)
print(player1cards5.. "	" ..player2cards5)
print(player1cards6.. "	" ..player2cards6)
print(player1cards7.. "	" ..player2cards7)
	print(test)
print("Score Player: " ..playerscore1.. "	Score Bank: " ..playerscore2)
end
repeat
shell.run("clear")
kartenziehen1()
scoreboard()
write("Continue? ")
yesno()
ende1()
until weristdran ~= 1
repeat
shell.run("clear")
kartenziehen2()
scoreboard()
	ende2()
until weristdran ~= 2 and weristdran > 1
repeat
ende3()
until weristdran ~= 3 and weristdran > 2
yesno()
For example if i choose Go in yesno() the next card get a value but sometimes i get the error (random in the scoreboard):

BlackJack:331: attempt to concatenate nil and string
i think the problem are the letters D K J A here:

	elseif random >= 41 and random <= 44 then
		dummy1(D)
		scores1(10)
	elseif random >= 45 and random <= 48 then
		dummy1(K)
		scores1(10)
	elseif random >= 49 and random <= 52 then
		dummy1(J)
		scores1(10)
	elseif random >= 53 and random <= 56 then
		dummy1(A)
		scores1(11)
pls. help :)/>/>
cya
DMKxD
Edited on 12 July 2012 - 11:40 AM
MaryuZ #9
Posted 12 July 2012 - 01:54 PM
Considering I'll mod it to fit the task and add ascii graphics in the form of actual cards to it can i use your code in a gambling machine capable of running multiple games that i'm developing?
DMKxD #10
Posted 13 July 2012 - 02:01 PM

playerscore1 = 0
playerscore2 = 0
player1scores0 = 0
player1scores1 = 0
player1scores2 = 0
player1scores3 = 0
player1scores4 = 0
player1scores5 = 0
player1scores6 = 0
player1scores7 = 0
player2scores0 = 0
player2scores1 = 0
player2scores2 = 0
player2scores3 = 0
player2scores4 = 0
player2scores5 = 0
player2scores6 = 0
player2scores7 = 0
player1cards0 = ""
player1cards1 = ""
player1cards2 = ""
player1cards3 = ""
player1cards4 = ""
player1cards5 = ""
player1cards6 = ""
player1cards7 = ""
player1cards8 = ""
player2cards0 = ""
player2cards1 = ""
player2cards2 = ""
player2cards3 = ""
player2cards4 = ""
player2cards5 = ""
player2cards6 = ""
player2cards7 = ""
weiter = true
endeplayer1 = false
endeplayer2 = false
random = 0
weristdran = 0
zahltimer = 1
test = ""
running = false
go = false
stop = true
player1verloren = false
player2verloren = false
copper = false
iron = false
gold = false
diamond = false
gamemode = ""
cursorY,cursorX = 0
function dummy1(a) --Translate the number a string for the scoreboard (Interface)
if player1cards0 == "" then
	 player1cards0 = a
  elseif player1cards1 == "" then
	    player1cards1 = a
elseif player1cards2 == "" then
	    player1cards2 = a

   elseif player1cards3 == "" then
	    player1cards3 = a

elseif player1cards4 == "" then
	    player1cards4 = a

elseif player1cards5 == "" then
	    player1cards5 = a
	  
elseif player1cards6 == "" then
	    player1cards6 = a

elseif player1cards7 == "" then
  player1cards7 = a
  end
end
function dummy2(B)/>/> --Translate the number a string for the scoreboard (Interface)
if player2cards0 == "" then
	 player2cards0 = b
elseif player2cards1 == "" then
	    player2cards1 = b
elseif player2cards2 == "" then
	    player2cards2 = b

elseif player2cards3 == "" then
	    player2cards3 = b

elseif player2cards4 == "" then
	    player2cards4 = b

elseif player2cards5 == "" then
  player2cards5 = b
	  
elseif player2cards6 == "" then
	    player2cards6 = b

elseif player2cards7 == "" then
	    player2cards7 = b
end
end
function scores1(c) --Translate the number into a score
if player1scores0 == 0 then
	 player1scores0 = c
elseif player1scores1 == 0 then
	    player1scores1 = c
elseif player1scores2 == 0 then
	    player1scores2 = c

elseif player1scores3 == 0 then
	    player1scores3 = c

elseif player1scores4 == 0 then
	    player1scores4 = c

elseif player1scores5 == 0 then
	    player1scores5 = c

elseif player1scores6 == 0 then
  player1scores6 = c

elseif player1scores7 == 0 then
	    player1scores7 = c
    end
playerscore1 = player1scores0 + player1scores1 + player1scores2 + player1scores3 + player1scores4 + player1scores5 + player1scores6 + player1scores7
end
function scores2(d) --Translate the number into a score
if player2scores0 == 0 then
	 player2scores0 = d
elseif player2scores1 == 0 then
	    player2scores1 = d
elseif player2scores2 == 0 then
	    player2scores2 = d

elseif player2scores3 == 0 then
	    player2scores3 = d

elseif player2scores4 == 0 then
	    player2scores4 = d

elseif player2scores5 == 0 then
	    player2scores5 = d

elseif player2scores6 == 0 then
	    player2scores6 = d

elseif player2scores7 == 0 then
	    player2scores7 = d
end
playerscore2 = player2scores0 + player2scores1 + player2scores2 + player2scores3 + player2scores4 + player2scores5 + player2scores6 + player2scores7
end
function kartenziehen1() --Create a random Card for Player2
random = math.random(56) + 1
if random == 0 then
  random = math.random(56) + 1
elseif random == 0 then
  random = math.random(56) + 1
elseif random >= 1 and random <= 4 then
  dummy1(2)
  scores1(2)
    elseif random >= 5 and random <= 8 then
	 dummy1(3)
	 scores1(3)
    elseif random >= 9 and random <= 12 then
	 dummy1(4)
	 scores1(4)
    elseif random >= 13 and random <= 16 then
	 dummy1(5)
	 scores1(5)
    elseif random >= 17 and random <= 20 then
	 dummy1(6)
	 scores1(6)
    elseif random >= 21 and random <= 24 then
	    dummy1(7)
	    scores1(7)
    elseif random >= 25 and random <= 28 then
	    dummy1(8)
	    scores1(8)
    elseif random >= 29 and random <= 32 then
	    dummy1(9)
	    scores1(9)
    elseif random >= 33 and random <= 36 then
	    dummy1(10)
	    scores1(10)
    elseif random >= 37 and random <= 40 then
	    dummy1("B")
	    scores1(10)
    elseif random >= 41 and random <= 44 then
	    dummy1("D")
	    scores1(10)
    elseif random >= 45 and random <= 48 then
	    dummy1("K")
	    scores1(10)
    elseif random >= 49 and random <= 52 then
	    dummy1("J")
	    scores1(10)
    elseif random >= 53 and random <= 56 then
	    dummy1("A")
	    scores1(11)
    end
end
function kartenziehen2() --Create a random Card for Player2 (Bot)
random = math.random(56) + 1
if random == 0 then
  random = math.random(56) + 1
elseif random == 0 then
  random = math.random(56) + 1
elseif random >= 1 and random <= 4 then
  dummy2(2)
  scores2(2)
    elseif random >= 5 and random <= 8 then
	 dummy2(3)
	 scores2(3)
    elseif random >= 9 and random <= 12 then
	 dummy2(4)
	 scores2(4)
    elseif random >= 13 and random <= 16 then
	 dummy2(5)
	 scores2(5)
    elseif random >= 17 and random <= 20 then
	 dummy2(6)
	 scores2(6)
    elseif random >= 21 and random <= 24 then
	    dummy2(7)
	    scores2(7)
    elseif random >= 25 and random <= 28 then
	    dummy2(8)
	    scores2(8)
    elseif random >= 29 and random <= 32 then
	    dummy2(9)
	    scores2(9)
    elseif random >= 33 and random <= 36 then
	    dummy2(10)
	    scores2(10)
    elseif random >= 37 and random <= 40 then
	    dummy2("B")
	    scores2(10)
    elseif random >= 41 and random <= 44 then
	    dummy2("D")
	    scores2(10)
    elseif random >= 45 and random <= 48 then
	    dummy2("K")
	    scores2(10)
    elseif random >= 49 and random <= 52 then
	    dummy2("J")
	    scores2(10)
    elseif random >= 53 and random <= 56 then
	    dummy2("A")
	    scores2(11)
end
end
function Wechseln() --Change between go == true / false and stop == true / false (Don't work correctly :/)
while weiter == true do
  if go == true then
   go = false
   stop = true
   weiter = false
break end
  if go == false then
   go = true
   stop = false
   weiter = false
break end
end
end
function yesno() --Change between Stop and Go (Don't work correctly :/)
repeat
  local e, key = os.pullEvent( "key" )
  if key == 203 or key == 205 then
   weiter = true
   Wechseln()
	 end
	 if go == true then
	  term.clearLine()
	  print("Continue? Yes")
	 elseif stop == true then
	  term.clearLine()
	  print("Continue? No")
	 end
until key == 28
ende1()
end
function ende1()
if stop == true or playerscore1 > 21 then
   if playerscore1 > 21 then
    print("You loose...")
	 sleep(3)
    shell.run("reboot")
  else
   print("Your score is saved, now let's see if you could beat the bank!")
   weristdran = 2
  end
end
end
function ende2()
if playerscore2 > 16 then
  if playerscore2 > 21 then
   print("You won!")
   sleep(1)
   gewinnausgabe()
   sleep(2)
   gewinnausgabe()
   shell.run("reboot")
   weristdran = 3
  elseif playerscore2 == 21 then
   print("You loose...")
   sleep(1)
   shell.run("reboot")
   weristdran = 3
  end
  weristdran = 3
end
end
function ende3()
if playerscore1 > playerscore2 or player2erloren == true then
   print("You won!")
   sleep(1)
  gewinnausgabe()
  sleep(2)
  gewinnausgabe()
  shell.run("reboot")
elseif playerscore1 == playerscore2 then
    print("Draw!")
    gewinnausgabe()
    sleep(2)
    shell.run("reboot")
end
end
function anfang()
  while copper == false and iron == false and gold == false and diamond == false do
   print("Insert a copper ingot, a iron ingot, a gold-ingot ot a diamond!")
   write("waiting")
   if rs.testBundledInput("back", colours.white) then
    copper = true
    weristdran = 1
   elseif rs.testBundledInput("back", colours.blue) then
    iron = true
    weristdran = 1
   elseif rs.testBundledInput("back", colours.green) then
    gold = true
    weristdran = 1
   elseif rs.testBundledInput("back", colours.red) then
    diamond = true
   end
  end
  if copper == true or iron == true or gold == true or diamond == true then
   weristdran = 1
   gamemodezuweisen()
   scoreboard()
  end
end
function gamemodezuweisen()
if copper == true and gamemode == "" then
  gamemode = "copper"
elseif iron == true and gamemode == "" then
	 gamemode = "iron"
elseif gold == true and gamemode == "" then
	 gamemode = "gold"
elseif diamond == true and gamemode == "" then
	 gamemode = "diamond"
end
end
function gewinnausgabe()
if chopper == true then
  rs.setBundledOutput("bottom", colors.white)
    elseif iron == true then
   rs.setBundledOutput("bottom", colors.blue)
  elseif gold == true then
   rs.setBundledOutput("bottom", colors.green)
  elseif diamond == true then
   rs.setBundledOutput("bottom", colors.red)
  end
  sleep(1)
  rs.setBundledOutput("bottom", 0)
end
function scoreboard() --Interface
print("BlackJack v1.0 by DMKxD")
print("Gamemode: " ..gamemode)
print("*********************************")
print("Player  Bot")
print(player1cards0.. "    " ..player2cards0)
print(player1cards1.. "    " ..player2cards1)
print(player1cards2.. "    " ..player2cards2)
print(player1cards3.. "    " ..player2cards3)
print(player1cards4.. "    " ..player2cards4)
print(player1cards5.. "    " ..player2cards5)
print(player1cards6.. "    " ..player2cards6)
print(player1cards7.. "    " ..player2cards7)
    print(test)
print("Score Player: " ..playerscore1.. "    Score Bank: " ..playerscore2)
end
repeat
start1()
shell.run("clear")
kartenziehen1()
scoreboard()
write("Continue? ")
yesno()
ende1()
until weristdran ~= 1 and weristdran > 0
repeat
shell.run("clear")
kartenziehen2()
scoreboard()
sleep(2)
    ende2()
until weristdran ~= 2 and weristdran > 1
repeat
ende3()
until weristdran ~= 3 and weristdran > 2
anfang()
if fixed all known bug and all worked fine, now i've some trouble with the anfang() function, because the output of CC is now "6"

function anfang()
  while copper == false and iron == false and gold == false and diamond == false do
   print("Insert a copper ingot, a iron ingot, a gold-ingot ot a diamond!")
   write("waiting")
   if rs.testBundledInput("back", colours.white) then
    copper = true
    weristdran = 1
   elseif rs.testBundledInput("back", colours.blue) then
    iron = true
    weristdran = 1
   elseif rs.testBundledInput("back", colours.green) then
    gold = true
    weristdran = 1
   elseif rs.testBundledInput("back", colours.red) then
    diamond = true
   end
  end
  if copper == true or iron == true or gold == true or diamond == true then
   weristdran = 1
   gamemodezuweisen()
   scoreboard()
  end
end

@MaryuZ You can use everything you need buddy :)/>/>
DMKxD #11
Posted 14 July 2012 - 01:54 PM
Push, pls. help :P/>/>