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

Program Issues

Started by jtdavis99, 05 April 2012 - 07:51 PM
jtdavis99 #1
Posted 05 April 2012 - 09:51 PM
I've tried everything I can think of, but it ALWAYS says there is an error on line 20. No clue why, hoping others could help me out :)/>/>

mini = math.random(1,50)
jackpot = math.random(1,1000)
money = 100
minis = 0
if minis > 2 then
mini = 0
end
term.clear()
term.setCursorPos(1,1)
print("Welcome to the lottery! Test your chances to win big!")
print("Would you like to play? (y/n)")
print("Cost: $10")
input = input.read()
if input == "y" then
term.clear()
term.setCursorPos(1,1)
money = money - 10
print("Okay then! Spinning the wheel...")
sleep(2)

if mini == 10 or mini == 20 then
  minis = minis + 1
  money + 100
  term.clear()
  term.setCursorPos(1,1)
  print("Oh wow! You got the mini-jackpot! Congrats!")
  term.clear()
  term.setCursorPos(1,1)
return

elseif mini ~= 10 and ~= 20 and jackpot ~= 1000 then
  term.clear()
  term.setCursorPos(1,1)
  print("Ooh, that's too bad. Better luck next time!")
return

elseif jackpot == 1000 then
  money = money + 1000
  term.clear()
  term.setCursorPos(1,1)
  print("Hacker...")
  term.clear()
  term.setCursorPos(1,1)
return

end
elseif input == "n" then
term.clear()
term.setCursorPos(1,1)
print("Oh, okay then.")
sleep(1)
os.reboot()
end
Luanub #2
Posted 05 April 2012 - 10:19 PM
Your missing and end for the if on line 14, you need it prior to starting the next if statement on line 21.

You also have an extra end on line 46


Never mind after a closer look at the logic,and you need to move the end on line 46 to then end of the code.

Okay to much of a hurry, its time to goto work.

The ends were okay. Here is the corrected code with comments in line. I did some reformatting thats not really needed, just made it easier to digest.

Spoiler

mini = math.random(1,50)
jackpot = math.random(1,1000)
money = 100
minis = 0
if minis > 2 then
mini = 0
end
term.clear()
term.setCursorPos(1,1)
print("Welcome to the lottery! Test your chances to win big!")
print("Would you like to play? (y/n)")
print("Cost: $10")
input = read()  -- removed the input.
if input == "y" then
term.clear()
term.setCursorPos(1,1)
money = money - 10
print("Okay then! Spinning the wheel...")
sleep(2)
    if mini == 10 or mini == 20 then
        minis = minis + 1
        money = money + 100 -- added money =
        term.clear()
        term.setCursorPos(1,1)
        print("Oh wow! You got the mini-jackpot! Congrats!")
        term.clear()
        term.setCursorPos(1,1)
        return
    elseif mini ~= 10 and mini ~= 20 and jackpot ~= 1000 then -- corrected and logic for the mini ~= 20
        term.clear()
        term.setCursorPos(1,1)
        print("Ooh, that's too bad. Better luck next time!")
        return
    elseif jackpot == 1000 then
        money = money + 1000
        term.clear()
        term.setCursorPos(1,1)
        print("Hacker...")
        term.clear()
        term.setCursorPos(1,1)
        return
    end
elseif input == "n" then
        term.clear()
        term.setCursorPos(1,1)
        print("Oh, okay then.")
        sleep(1)
        os.reboot()
end
Edited on 05 April 2012 - 08:28 PM
jtdavis99 #3
Posted 05 April 2012 - 10:32 PM
Thank you so much! Just one thing, how would I make it so it returned to the beginning of the program with all the changed variables kept changed?
Luanub #4
Posted 05 April 2012 - 10:42 PM
Thank you so much! Just one thing, how would I make it so it returned to the beginning of the program with all the changed variables kept changed?

I thought you might ask that, try this..

Spoiler

local mini = math.random(1,50)
local jackpot = math.random(1,1000)
local money = 100
local minis = 0
if minis > 2 then
mini = 0
end
while true do
term.clear()
term.setCursorPos(1,1)
print("Welcome to the lottery! Test your chances to win big!")
print("Would you like to play? (y/n)")
print("Cost: $10")
print ("You have $"..money)
input = read()
if input == "y" then
    if money <= 0 then
        print ("You're Broke Better Luck Next Time")
        sleep(0.5)
        shell.run("clear")
        break
    else
    term.clear()
    term.setCursorPos(1,1)
    money = money - 10
    print("Okay then! Spinning the wheel...")
    sleep(0.5)
    mini = math.random(1,50)
    jackpot = math.random(1,1000)
    sleep(2)
    if mini == 10 or mini == 20 then
        minis = minis + 1
        money = money + 100
        term.clear()
        term.setCursorPos(1,1)
        print("Oh wow! You got the mini-jackpot! Congrats!")
        sleep(2)
        term.clear()
        term.setCursorPos(1,1)
        --return
    elseif mini ~= 10 and mini ~= 20 and jackpot ~= 1000 then
        term.clear()
        term.setCursorPos(1,1)
        print("Ooh, that's too bad. Better luck next time!")
        sleep(2)
        --return
    elseif jackpot == 1000 then
        money = money + 1000
        term.clear()
        term.setCursorPos(1,1)
        print("Hacker...")
        sleep(2)
        term.clear()
        term.setCursorPos(1,1)
        --return
    end
    end
elseif input == "n" then
        term.clear()
        term.setCursorPos(1,1)
        print("Oh, okay then.")
        sleep(1)
        break
end
end

You can even add some commands to save the money var in a file so the amount of money is saved when you exit the game. I would show you how but I got to take off for work, there should be some examples in the programs/api section of the the forums.
jtdavis99 #5
Posted 05 April 2012 - 10:45 PM
Thanks a ton. I would've ragequit if it weren't for you XD