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

Please Help Me!

Started by Timo_Ho, 29 July 2014 - 10:40 AM
Timo_Ho #1
Posted 29 July 2014 - 12:40 PM
I got a problem with my OS it keeps saying main.lua 10 attempt to index ? (a nil value)

The whole OS starts like so:

first the startup:

Spoilerif fs.exists("src/advanced") then
fs.delete("src/advanced")
end
shell.run("pastebin get 8dKmgJzM dl.tmp")
if fs.exists("dl.tmp") then
fs.delete("dl.tmp")
x = 1
else
x = 0
end
if x == 1 then
fs.delete("startup")
shell.run("pastebin get HmZbq89u startup")
end
if x == 1 then
if fs.exists("src/cAPI") then
fs.delete("src/cAPI")
end
shell.run("pastebin get ea9LncrA src/cAPI")
end
if x == 1 and fs.exists("timosdls") then
fs.delete("timosdls")
shell.run("pastebin get YewJFgvW tstore")
end
if fs.exists("src/ver11") then
sleep(0,2)
elseif x == 1 then
shell.run("pastebin get Jm8Y1MZH src/ver11")
end
if x == 1 then
fs.delete("tstore")
shell.run("pastebin get YewJFgvW tstore")
end
if fs.exists("src/dllt") then
fs.delete("src/dllt")
end
if fs.exists("src/dlth") then
fs.delete("src/dlth")
end
if x == 1 then
shell.run("pastebin get 71GxxQMg src/dllt")
shell.run("pastebin get 5xCJPz5v src/dlth")
end
if x == 1 and fs.exists("cardtania") then
fs.delete("cardtania")
shell.run("pastebin get gxQ1PdBD cardtania")
end
if not fs.exists("src/animatecraft/v2") then
if fs.exists("animatecraft") then
fs.delete("animatecraft")
fs.delete("src/animatecraft/new")
fs.delete("src/animatecraft/edit")
fs.delete("src/animatecraft/player")
fs.delete("src/animatecraft/reimg")
shell.run("pastebin run JD12pdFM")
shell.run("mkdir src/animatecraft/v2")
end
end
shell.run("clear")
print("CraftOS")
print(" ")
if fs.exists("src/TOS") then
shell.run("pastebin get jFLvG79m stupRAW")
if fs.exists("stupRAW") then
fs.delete("TOSstartup")
fs.copy("stupRAW", "TOSstartup")
fs.delete("stupRAW")
end
print("BIOS update complete")
shell.run("TOSstartup")
end
(This file updates everything)

second the TOSstartup:

Spoilershell.run("pastebin get 1S3EPhMg mainRAW")
if fs.exists("mainRAW") then
fs.delete("src/TOS/main.lua")
fs.copy("mainRAW", "src/TOS/main.lua")
fs.delete("mainRAW")
end
if fs.exists("src/TOS/ink") and not fs.exists("src/TOS/programs/ink") then
fs.move("src/TOS/ink", "src/TOS/programs/ink")
end
if fs.exists("mplayer") and not fs.exists("src/TOS/programs/mplayer") then
fs.move("mplayer", "src/TOS/programs/mplayer")
end
if not fs.exists("src/TOS/programs") then
shell.run("mkdir src/TOS/programs")
end
if not fs.exists("mplayer") then
shell.run("pastebin get 4JehP0i3 mplayer")
end
if not fs.exists("src/TOS/ink") then
shell.run("pastebin get JxzXPv03 src/TOS/ink")
end
if fs.exists("src/TOS/BG.img") then
fs.delete("src/TOS/BG.img")
end
if not fs.exists("cardtania") then
shell.run("pastebin run 08mhZzbV")
end
print("OS update complete")
sleep(2)
function login()
write("username: ")
uname = read()
if fs.exists("src/users/"..uname) then
write("password: ")
pw = read("*")
if fs.exists("src/users/"..uname.."/"..pw) then
print("access granted")
else
os.reboot()
end
else
os.reboot()
end
end
function create()
write("username: ")
uname = read()
if not fs.exists("src/users/"..uname) then
write("password: ")
pw = read("*")
shell.run("mkdir src/users/"..uname.."/"..pw)
else
print("user already exists")
end
end
shell.run("clear")
os.loadAPI("src/cAPI")
dBoot = cAPI.menu("boot in CraftOS", "boot in TOS")
if dBoot == 1 then error() end
shell.run("clear")
if term.isColor() then
term.setBackgroundColor(colors.blue)
term.setTextColor(colors.lightGray)
end
shell.run("clear")
print("WELCOME!")
print(" ")
print(" ")
print(" press any key to login")
os.pullEvent("key")
shell.run("clear")
mPos = cAPI.menu("login", "create account")
if mPos == 1 then
login()
else
create()
end
shell.run("clear")
shell.run("src/TOS/main.lua "..uname.." "..pw)
(This updates th OS and is used for multiboot and login)

and third the main.lua:

SpoilertArgs = {…}
uname = tArgs[1]
pw = tArgs[2]
function loadOptions(…)
arg = {…}
file = fs.open("src/users/"..arg[1].."/"..arg[2].."/settings", "r")
data = file.readAll()
file.close()
settings = textutils.unserialize(data)
bg = settings[1]
tx = settings[2]
end
function editOptions(…)
arg = {…}
fs.delete("src/users/"..arg[1].."/"..arg[2].."/settings")
shell.run("clear")
print("background: ")
print("aviable colors: ")
print("white, orange, magenta, lightBlue, yellow, lime, pink, gray,")
print("lightGray, cyan, purple, blue, brown, green, red, black")
print(" ")
write("your choose: ")
cho = read()
bg = "colors."..cho
shell.run("clear")
print("Text: ")
print("aviable colors: ")
print("white, orange, magenta, lightBlue, yellow, lime, pink, gray,")
print("lightGray, cyan, purple, blue, brown, green, red, black")
print(" ")
write("your choose: ")
cho = read()
tx = "colors."..cho
settings = {bg, tx}
file = fs.open("src/users/"..arg[1].."/"..arg[2].."/settings", "w")
file.writeLine(textutils.serialize(settings))
file.close()
shell.run("clear")
end
sleep(1)
shell.run("clear")
os.loadAPI("src/cAPI")
if fs.exists("src/users/"..uname.."/"..pw.."/settings") then
loadOptions(uname, pw)
else
bg = colors.blue
tx = colors.lightGray
end
function games()
mPos = cAPI.menu("Worm", "cardtania")
if mPos == 1 then
if term.isColor() then
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
end
shell.run("clear")
shell.run("worm")
else
shell.run("cardtania")
end
end
function programlist()
shell.run("clear")
allprogs = fs.list("src/TOS/programs")
print("installed programs: ")
x = 1
while true do
if allprogs[x] == nil then break end
print(allprogs[x])
x = x + 1
end
write("please enter the program that you want to run: ")
torun = read()
shell.run("src/TOS/programs/"..torun)
end
while true do
if term.isColor() then
term.setBackgroundColor(bg)
term.setTextColor(tx)
end
shell.run("clear")
mPos = cAPI.menu("tstore", "explorer", "programs", "Games", "shutdown", "reboot", "CraftOS", "settings")
shell.run("clear")
if mPos == 1 then
shell.run("tstore")
elseif mPos == 2 then
shell.run("src/TOS/icebrowser")
elseif mPos == 5 then
os.shutdown()
elseif mPos == 6 then
os.reboot()
elseif mPos == 7 then
if term.isColor() then
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
end
shell.run("clear")
error()
elseif mPos == 8 then
shell.run("clear")
editOptions(uname,pw)
shell.run("clear")
elseif mPos == 4 then
games()
elseif mPos == 3 then
programlist()
end
end
(This is the main OS) This is the program what is not working yet


Please Help Me!!
hilburn #2
Posted 29 July 2014 - 01:09 PM
Firstly It's nice for formatting if you use the [.CODE][./CODE] tags, but that's not really important

Your problem comes in TOSstartup with your shell.run, rather than concatenate the arguments onto the run command, the syntax is shell.run(string command [, string args1, string args2, …]) this means your main program is not getting any arguments
Timo_Ho #3
Posted 30 July 2014 - 01:43 PM
Firstly It's nice for formatting if you use the [.CODE][./CODE] tags, but that's not really important

Your problem comes in TOSstartup with your shell.run, rather than concatenate the arguments onto the run command, the syntax is shell.run(string command [, string args1, string args2, …]) this means your main program is not getting any arguments

ok that helped but there is still an error now it says main.lua 39 attempt to index ? (a nil value)

here's the new code:

Spoilerif fs.exists("src/advanced") then
fs.delete("src/advanced")
end
shell.run("pastebin get 8dKmgJzM dl.tmp")
if fs.exists("dl.tmp") then
fs.delete("dl.tmp")
x = 1
else
x = 0
end
if x == 1 then
fs.delete("startup")
shell.run("pastebin get HmZbq89u startup")
end
if x == 1 then
if fs.exists("src/cAPI") then
fs.delete("src/cAPI")
end
shell.run("pastebin get ea9LncrA src/cAPI")
end
if x == 1 and fs.exists("timosdls") then
fs.delete("timosdls")
shell.run("pastebin get YewJFgvW tstore")
end
if fs.exists("src/ver11") then
sleep(0,2)
elseif x == 1 then
shell.run("pastebin get Jm8Y1MZH src/ver11")
end
if x == 1 then
fs.delete("tstore")
shell.run("pastebin get YewJFgvW tstore")
end
if fs.exists("src/dllt") then
fs.delete("src/dllt")
end
if fs.exists("src/dlth") then
fs.delete("src/dlth")
end
if x == 1 then
shell.run("pastebin get 71GxxQMg src/dllt")
shell.run("pastebin get 5xCJPz5v src/dlth")
end
if x == 1 and fs.exists("cardtania") then
fs.delete("cardtania")
shell.run("pastebin get gxQ1PdBD cardtania")
end
if not fs.exists("src/animatecraft/v2") then
if fs.exists("animatecraft") then
fs.delete("animatecraft")
fs.delete("src/animatecraft/new")
fs.delete("src/animatecraft/edit")
fs.delete("src/animatecraft/player")
fs.delete("src/animatecraft/reimg")
shell.run("pastebin run JD12pdFM")
shell.run("mkdir src/animatecraft/v2")
end
end
shell.run("clear")
print("CraftOS")
print(" ")
if fs.exists("src/TOS") then
shell.run("pastebin get jFLvG79m stupRAW")
if fs.exists("stupRAW") then
fs.delete("TOSstartup")
fs.copy("stupRAW", "TOSstartup")
fs.delete("stupRAW")
end
print("BIOS update complete")
shell.run("TOSstartup")
end
this is the startup

Spoilershell.run("pastebin get 1S3EPhMg mainRAW")
if fs.exists("mainRAW") then
fs.delete("src/TOS/main.lua")
fs.copy("mainRAW", "src/TOS/main.lua")
fs.delete("mainRAW")
end
if fs.exists("src/TOS/ink") and not fs.exists("src/TOS/programs/ink") then
fs.move("src/TOS/ink", "src/TOS/programs/ink")
end
if fs.exists("mplayer") and not fs.exists("src/TOS/programs/mplayer") then
fs.move("mplayer", "src/TOS/programs/mplayer")
end
if not fs.exists("src/TOS/programs") then
shell.run("mkdir src/TOS/programs")
end
if not fs.exists("mplayer") then
shell.run("pastebin get 4JehP0i3 mplayer")
end
if not fs.exists("src/TOS/ink") then
shell.run("pastebin get JxzXPv03 src/TOS/ink")
end
if fs.exists("src/TOS/BG.img") then
fs.delete("src/TOS/BG.img")
end
if not fs.exists("cardtania") then
shell.run("pastebin run 08mhZzbV")
end
print("OS update complete")
sleep(2)
function login()
write("username: ")
uname = read()
if fs.exists("src/users/"..uname) then
write("password: ")
pw = read("*")
if fs.exists("src/users/"..uname.."/"..pw) then
print("access granted")
else
os.reboot()
end
else
os.reboot()
end
end
function create()
write("username: ")
uname = read()
if not fs.exists("src/users/"..uname) then
write("password: ")
pw = read("*")
shell.run("mkdir src/users/"..uname.."/"..pw)
else
print("user already exists")
end
end
shell.run("clear")
os.loadAPI("src/cAPI")
dBoot = cAPI.menu("boot in CraftOS", "boot in TOS")
if dBoot == 1 then error() end
shell.run("clear")
if term.isColor() then
term.setBackgroundColor(colors.blue)
term.setTextColor(colors.lightGray)
end
shell.run("clear")
print("WELCOME!")
print(" ")
print(" ")
print(" press any key to login")
os.pullEvent("key")
shell.run("clear")
mPos = cAPI.menu("login", "create account")
if mPos == 1 then
login()
else
create()
end
shell.run("clear")
shell.run("src/TOS/main.lua ["..uname.." "..pw.."]")
this is the TOSstartup

SpoilertArgs = {…}
uname = tArgs[1]
pw = tArgs[2]
function loadOptions(…)
arg = {…}
file = fs.open("src/users/"..arg[1].."/"..arg[2].."/settings", "r")
data = file.readAll()
file.close()
settings = textutils.unserialize(data)
bg = settings[1]
tx = settings[2]
bg = tonumber(bg)
tx = tonumber(tx)
end
function editOptions(…)
arg = {…}
fs.delete("src/users/"..arg[1].."/"..arg[2].."/settings")
shell.run("clear")
print("background: ")
print("aviable colors: ")
print("white, orange, magenta, lightBlue, yellow, lime, pink, gray,")
print("lightGray, cyan, purple, blue, brown, green, red, black")
print(" ")
write("your choose: ")
cho = read()
bg = "colors."..cho
shell.run("clear")
print("Text: ")
print("aviable colors: ")
print("white, orange, magenta, lightBlue, yellow, lime, pink, gray,")
print("lightGray, cyan, purple, blue, brown, green, red, black")
print(" ")
write("your choose: ")
cho = read()
tx = "colors."..cho
settings = {bg, tx}
settingsdata = textutils.serialize(settings)
file = fs.open("src/users/"..arg[1].."/"..arg[2].."/settings", "w")
file.writeLine(settingsdata)
file.close()
shell.run("clear")
loadOptions()
end
sleep(1)
shell.run("clear")
os.loadAPI("src/cAPI")
if fs.exists("src/users/"..uname.."/"..pw.."/settings") then
loadOptions(uname, pw)
else
bg = colors.blue
tx = colors.lightGray
end
function games()
mPos = cAPI.menu("Worm", "cardtania")
if mPos == 1 then
if term.isColor() then
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
end
shell.run("clear")
shell.run("worm")
else
shell.run("cardtania")
end
end
function programlist()
shell.run("clear")
allprogs = fs.list("src/TOS/programs")
print("installed programs: ")
x = 1
while true do
if allprogs[x] == nil then break end
print(allprogs[x])
x = x + 1
end
write("please enter the program that you want to run: ")
torun = read()
shell.run("src/TOS/programs/"..torun)
end
while true do
if term.isColor() then
term.setBackgroundColor(bg)
term.setTextColor(tx)
end
shell.run("clear")
mPos = cAPI.menu("tstore", "explorer", "programs", "Games", "shutdown", "reboot", "CraftOS", "settings")
shell.run("clear")
if mPos == 1 then
shell.run("tstore")
elseif mPos == 2 then
shell.run("src/TOS/icebrowser")
elseif mPos == 5 then
os.shutdown()
elseif mPos == 6 then
os.reboot()
elseif mPos == 7 then
if term.isColor() then
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
end
shell.run("clear")
error()
elseif mPos == 8 then
shell.run("clear")
editOptions(uname,pw)
shell.run("clear")
elseif mPos == 4 then
games()
elseif mPos == 3 then
programlist()
end
end
this is the main.lua
Edited on 30 July 2014 - 12:12 PM
theoriginalbit #4
Posted 30 July 2014 - 04:40 PM
the problem is due to the fact that the file could not be created. the most common reason a file can only be created is if one of the folders it resides in does not exist. so you have to make sure you create any appropriate folders prior to trying to open the file.
Cranium #5
Posted 30 July 2014 - 04:45 PM
Likely you don't have enough arguments being passed to the fs.open() function you're calling on line 38.
Timo_Ho #6
Posted 30 July 2014 - 07:47 PM
the problem is due to the fact that the file could not be created. the most common reason a file can only be created is if one of the folders it resides in does not exist. so you have to make sure you create any appropriate folders prior to trying to open the file.
Die you mean that i only need to create that setting file?
(the folders are already there.)
Edited on 30 July 2014 - 05:49 PM
Timo_Ho #7
Posted 24 August 2014 - 12:21 PM
ok i've removed the function from my os. no more help needed thanks!!