15 posts
Posted 02 November 2012 - 07:47 AM
Hello, my program is an all purpose OS that currently contains a calculator, a timer and a guess the number game. I tried running it, but after typing "go" to get in the program, it said "attempt to call nil" on line 173. Here is the code:
function guess()
do
numb = math.random(1,100)
tries = 1
triesmax = 7
version = 1.1
win = false
end
do
term.clear()
textutils.slowPrint("———————————–")
textutils.slowPrint("| Geuss the Number |")
textutils.slowPrint("———————————–")
print("Enter to continue")
io.read()
print("You have 6 guesses. Guess the number before you run out of guesses")
end
while true do
if tries > triesmax then
break
else
print("Guess. [1 - 100, whole number]")
guess = io.read()
guess = tonumber(guess)
if guess == numb then
win = true
break
else
print("Incorrect")
if guess > numb then
print("Your guess was too high")
elseif guess < numb then
print("Your guess was too low")
else
print("This is a bug. Inform the WILL OS lab")
end
tries = tries + 1
end
end
end
do
term.clear()
textutils.slowPrint("GAME OVER")
if win == true then
print("YOU WIN!")
else
print("YOU LOSE")
end
end
function options1()
input = read()
if input == "t" then
term.clear()
term.setCursorPos(1,1)
timer()
end
if input == "c" then
term.clear()
term.setCursorPos(1,1)
calculator()
end
if input == "?" then
term.clear()
term.setCursorPos(1,1)
Guess()
end
end
function home()
print "—————————————–"
print "|,.,.,.,.,.,.,.,.WILL OS ,.,.,.,.,.,.,.,|"
print "|[T] Timer | |"
print "|[C] Caculator | |"
print "|[?] Geuss the number| |"
print "—————————————–"
options1()
end
function title()
term.clear()
term.setCursorPos(1,1)
home()
end
function timer()
minutes = 0
hours = 0
function clock()
for seconds = 0, 60, 1 do
shell.run("clear")
print "WILL OS (copyright 2012)"
print "———————————"
print (hours, ":",minutes,":", seconds)
print "———————————"
print "ATTENTION: You must still use CTRL-T"
print "to exit this program"
print "A fix is on it's way!"
if seconds == (60) then
minutes = minutes + 1
clock()
end
if minutes == (60) then
hours = hours + 1
minutes = 0
end
sleep(1)
end
seconds = 0
end
clock()
end
end
function calculator()
print "WILL OS (copyright 2012)"
print "Do you want to add, subtract, multiply, or divide?"
op = read()
print ""
print "Enter first number"
num1 = tonumber(read())
print ""
print "Enter second number"
num2 = tonumber(read())
print ""
if op == "add" then
result = num1+num2
print(result)
sleep(4)
title()
end
if op == "multiply" then
result = num1*num2
print(result)
sleep(4)
title()
end
if op == "divide" then
result = num1/num2
print(result)
sleep(4)
title()
end
if op == "subtract" then
result = num1-num2
print(result)
sleep(4)
title()
end
end
print "——————————————-"
print "| Welcome to WILL OS! |"
print "——————————————-"
print "Current build - WILLOSDEVBUILD2"
print "Current Version - WILL OS ALPHA 2"
print "[go] Get Started!"
print "[info] Information. Read before use"
if input == "go" then
title()
end
if input == "info" then
info()
end
52 posts
Location
Scotland
Posted 02 November 2012 - 08:02 AM
What is on line 173? (As much as i would love to count the lines I can't really be bothered)
15 posts
Posted 02 November 2012 - 08:08 AM
line 173 is title()
under the if input == "go" bit
52 posts
Location
Scotland
Posted 02 November 2012 - 08:22 AM
if input == "go" bit then?
nvm lol
52 posts
Location
Scotland
Posted 02 November 2012 - 08:26 AM
try replacing that part with:
if input == "go" then
title()
elseif input == "info" then
info()
end
15 posts
Posted 02 November 2012 - 08:30 AM
ok thanks ill try it
15 posts
Posted 02 November 2012 - 08:37 AM
it's still doing it, but as soon as i boot the program up. I cant even input "go".
52 posts
Location
Scotland
Posted 02 November 2012 - 09:02 AM
thats really weird.
52 posts
Location
Scotland
Posted 02 November 2012 - 09:05 AM
are you sure that you have declared the variable 'input'?
put 'input = read()' before the 'if input == "go" bit
52 posts
Location
Scotland
Posted 02 November 2012 - 09:07 AM
then it should work
52 posts
Location
Scotland
Posted 02 November 2012 - 09:48 AM
Success?
15 posts
Posted 02 November 2012 - 10:00 AM
hang on, ill try it
15 posts
Posted 02 November 2012 - 10:05 AM
it's still giving the "attempt to call nil" message, but the first screen is working
this is wierd
318 posts
Location
Somewhere on the planet called earth
Posted 02 November 2012 - 10:17 AM
Success?
Quad post! instead of quad post use the old edit button.
To op. Code tags ( [*code] –code [*/code] ) REmove the *s
Ask a pro section much better, ans faster, and the correct place to post this
Spoilers for long code. [*spoiler] –code [/*spoiler] remove 's
6 posts
Posted 02 November 2012 - 10:27 AM
Try this one, it seems to work
Spoiler
function guess()
numb = math.random(1,100)
tries = 1
triesmax = 7
version = 1.1
win = false
term.clear()
textutils.slowPrint("-----------------------------------")
textutils.slowPrint("| Guess the Number |")
textutils.slowPrint("-----------------------------------")
print("Enter to continue")
io.read()
print("You have 6 guesses. Guess the number before you run out of guesses")
while true do
if tries > triesmax then
break
else
print("Guess. [1 - 100, whole number]")
guess = io.read()
guess = tonumber(guess)
if guess == numb then
win = true
break
else
print("Incorrect")
if guess > numb then
print("Your guess was too high")
elseif guess < numb then
print("Your guess was too low")
else
print("This is a bug. Inform the WILL OS lab")
end
tries = tries + 1
end
end
end
term.clear()
textutils.slowPrint("GAME OVER")
if win == true then
print("YOU WIN!")
else
print("YOU LOSE")
end
end
function timer()
minutes = 0
hours = 0
function clock()
for seconds = 0, 60, 1 do
shell.run("clear")
print "WILL OS (copyright 2012)"
print "---------------------------------"
print (hours, ":",minutes,":", seconds)
print "---------------------------------"
print "ATTENTION: You must still use CTRL-T"
print "to exit this program"
print "A fix is on it's way!"
if seconds == (60) then
minutes = minutes + 1
clock()
end
if minutes == (60) then
hours = hours + 1
minutes = 0
end
sleep(1)
end
seconds = 0
end
clock()
end
function calculator()
print "WILL OS (copyright 2012)"
print "Do you want to add, subtract, multiply, or divide?"
op = read()
print ""
print "Enter first number"
num1 = tonumber(read())
print ""
print "Enter second number"
num2 = tonumber(read())
print ""
if op == "add" then
result = num1+num2
print(result)
sleep(4)
title()
end
if op == "multiply" then
result = num1*num2
print(result)
sleep(4)
title()
end
if op == "divide" then
result = num1/num2
print(result)
sleep(4)
title()
end
if op == "subtract" then
result = num1-num2
print(result)
sleep(4)
title()
end
end
function options1()
input = read()
if input == "t" then
term.clear()
term.setCursorPos(1,1)
timer()
end
if input == "c" then
term.clear()
term.setCursorPos(1,1)
calculator()
end
if input == "?" then
term.clear()
term.setCursorPos(1,1)
guess()
end
end
function home()
print "-----------------------------------------"
print "|,.,.,.,.,.,.,.,.WILL OS ,.,.,.,.,.,.,.,|"
print "|[T] Timer | |"
print "|[C] Caculator | |"
print "|[?] Geuss the number| |"
print "-----------------------------------------"
options1()
end
function title()
term.clear()
term.setCursorPos(1,1)
home()
end
print "-------------------------------------------"
print "| Welcome to WILL OS! |"
print "-------------------------------------------"
print "Current build - WILLOSDEVBUILD2"
print "Current Version - WILL OS ALPHA 2"
print "[go] Get Started!"
print "[info] Information. Read before use"
input = read()
if input == "go" then
title()
elseif input == "info" then
info()
end
2088 posts
Location
South Africa
Posted 02 November 2012 - 11:25 AM
Where have you defined a function for info() :?
Btw this should be in Ask a Pro.
52 posts
Location
Scotland
Posted 02 November 2012 - 12:16 PM
lol soz sjele
389 posts
Location
Norway
Posted 02 November 2012 - 07:55 PM
Do not ask questions about code in programs section, moved to ask a pro.
15 posts
Posted 03 November 2012 - 02:29 AM
ok, sorry, i'm pretty new here
15 posts
Posted 03 November 2012 - 02:30 AM
I haven't defined the info() function yet, but that doesn't appear to have made a difference
15 posts
Posted 03 November 2012 - 02:54 AM
Thanks Laywan, It worked!