Pages: 1
Topic closed
print(" /\\ /\\ ath")
print("/ \\/ \\ adness")
print("How high should the numbers be? (not the answer): ")
n = io.read("*n")
if (n == nil) then
print("No number found. Choosing 10.")
n = 10
end
function prob()
math.randomseed(tonumber(tostring(os.time()):reverse():sub(1,6))) -- Better random numbers
print("\n")
x = math.random(4)
if (x == 1) then
x = "+"
elseif (x == 2) then
x = "-"
elseif (x == 3) then
x = "*"
elseif (x == 4) then
x = "/"
end
x = tostring(math.random(n) .. x .. math.random(n))
print(x)
y = io.read("*n")
x = loadstring(x)()
if (y == x) then
print(y .. " is correct.")
else
print(y .. " is incorrect.")
end
prob()
end
prob()After I try to type in an answer to the first problem, the program throws an error. This is the output:
...\Desktop\Hunter - Other\Lua stuff\test.lua:27: attempt to call a nil value
stack traceback:
...\Desktop\Hunter - Other\Lua stuff\test.lua:27: in function 'prob'
...\Desktop\Hunter - Other\Lua stuff\test.lua:36: in main chunk
[C]: in function 'dofile'
stdin:1: in main chunk
[C]: ?This is stdin:
dofile("C:\\Users\\Owner\\Desktop\\Hunter - Other\\Lua stuff\\test.lua")Does anyone know how I can fix this?
Offline
Topic closed
Pages: 1