Posted 12 July 2012 - 12:17 AM
I have written this code for a gambling machine but when i try and run it it won't update the global variable credits…it keeps reinialising it…why?
t = {1,2,1,3,2,1,2,3,1}
credits=15
l=0
m=0
r=0
pa=0
bet=1
q={
"|Q.--. |",
"| (\\/) |",
"| :\\/: |",
"| '--'Q|"
}
k={
"|K.--. |",
"| :/\\: |",
"| :\\/: |",
"| '--'K|"
}
a={
"|A.--. |",
"| :/\\: |",
"| (__) |",
"| '--'A|"
}
g = {q,q,k,q,a,k,q,k,a,q,q}
function sb(bet)
if rs.testBundledInput("right", color.blue) then
if bet==1 then
bet=2
elseif bet==2 then
bet=5
elseif bet==5 then
bet=10
else bet=1
end
end
end
function play(bet,credits)
if (credits-bet)>=0 then
credits=credits-bet
l = math.random(1,9)
m = math.random(1,9)
r = math.random(1,9)
if t[l]==t[m] then
if t[m]==t[r] then
if t[l]==1 then
credits=credits+(bet*10)
elseif t[l]==2 then
credits=credits+(bet*25)
else credits=credits+(bet*75)
end
end
end
end
drawplay(l,m,r,bet,credits)
end
function pay()
local i
pa=credits/10
credits=math.fmod(credits,10)
for i=1, pa, 1 do
rs.setBundledOutput("bottom", colors.green)
sleep(1)
rs.setBundledOutput("bottom", 0)
sleep(1)
end
end
function logo(bet,credits)
term.clear()
print(" ")
print(" .------..------..------..------..------..------. ")
print(" |M.--. ||A.--. ||R.--. ||Y.--. ||U.--. ||Z.--. | ")
print(" | (\\/) || (\\/) || :)/>/>): || (\\/) || (\\/) || B)/>/>): | ")
print(" | :\\/: || :\\/: || ()() || :\\/: || :\\/: || ()() | ")
print(" | '--'M|| '--'A|| '--'R|| '--'Y|| '--'U|| '--'Z| ")
print(" '------''------''------''------''------''------' ")
print(" ")
print(" .------..------..------..------..------. ")
print(" |S.--. ||L.--. ||O.--. ||T.--. ||S.--. | ")
print(" | :/\\: || :/\\: || :/\\: || :/\\: || :/\\: | ")
print(" | :\\/: || (__) || :\\/: || (__) || :\\/: | ")
print(" | '--'S|| '--'L|| '--'O|| '--'T|| '--'S| ")
print(" '------''------''------''------''------' ")
print(" ")
print(".------..------..------..------..------..------..------.")
print("|M.--. ||A.--. ||C.--. ||H.--. ||I.--. ||N.--. ||E.--. |")
print("| (\\/) || (\\/) || :/\\: || :/\\: || (\\/) || B)/>/>): || (\\/) |")
print("| :\\/: || :\\/: || :\\/: || (__) || :\\/: || ()() || :\\/: |")
print("| '--'M|| '--'A|| '--'C|| '--'H|| '--'I|| '--'N|| '--'E|")
print("'------''------''------''------''------''------''------'")
print(" ")
print("########################################################")
print("########################################################")
print("### ###")
if bet==10 then
print("### BET : ",bet," ###")
else
print("### BET : ",bet," ###")
end
print("### ###")
if credits<10 then
print("### CREDITS : ",credits," ###")
elseif credits<100 then
print("### CREDITS : ",credits," ###")
elseif credits<1000 then
print("### CREDITS : ",credits," ###")
elseif credits<10000 then
print("### CREDITS : ",credits," ###")
else
print("### CREDITS : ",credits," ###")
end
print("### ###")
print("########################################################")
write("########################################################")
sleep(1)
end
function drawplay(l,m,r,bet,credits)
l=l+1
m=m+1
r=r+1
term.clear()
print(" ")
print(" .------. # .------. # .------. ")
print(" ",g[l-1][1]," # ",g[m-1][1]," # ",g[r-1][1]," ")
print(" ",g[l-1][2]," # ",g[m-1][2]," # ",g[r-1][2]," ")
print(" ",g[l-1][3]," # ",g[m-1][3]," # ",g[r-1][3]," ")
print(" ",g[l-1][4]," # ",g[m-1][4]," # ",g[r-1][4]," ")
print(" '------' # '------' # '------' ")
print(" \\\\ # # // ")
print(" \\\\ .------. # .------. # .------. // ")
print(" \\\\ ",g[l][1]," # ",g[m][1]," # ",g[r][1]," // ")
print(" \\\\\\\\\\ ",g[l][2]," # ",g[m][2]," # ",g[r][2]," ///// ")
print(" ///// ",g[l][3]," # ",g[m][3]," # ",g[r][3]," \\\\\\\\\\ ")
print(" // ",g[l][4]," # ",g[m][4]," # ",g[r][4]," \\\\ ")
print(" // '------' # '------' # '------' \\\\ ")
print(" // # # \\\\ ")
print(" .------. # .------. # .------. ")
print(" ",g[l+1][1]," # ",g[m+1][1]," # ",g[r+1][1]," ")
print(" ",g[l+1][2]," # ",g[m+1][2]," # ",g[r+1][2]," ")
print(" ",g[l+1][3]," # ",g[m+1][3]," # ",g[r+1][3]," ")
print(" ",g[l+1][4]," # ",g[m+1][4]," # ",g[r+1][4]," ")
print(" '------' # '------' # '------' ")
print(" ")
print("########################################################")
print("########################################################")
print("### ###")
if bet==10 then
print("### BET : ",bet," ###")
else
print("### BET : ",bet," ###")
end
print("### ###")
if credits<10 then
print("### CREDITS : ",credits," ###")
elseif credits<100 then
print("### CREDITS : ",credits," ###")
elseif credits<1000 then
print("### CREDITS : ",credits," ###")
elseif credits<10000 then
print("### CREDITS : ",credits," ###")
else
print("### CREDITS : ",credits," ###")
end
print("### ###")
print("########################################################")
write("########################################################")
sleep(2)
end
logo(bet,credits)
while credits>0 do
play(bet,credits)
end