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

Weird glitch, or am I doing everything wrong? (shell.run)

Started by MarcoPolo0306, 23 May 2018 - 04:20 PM
MarcoPolo0306 #1
Posted 23 May 2018 - 06:20 PM
Notice: I know what the "Read this post before asking questions" says, but I need help with this.

My API refuses to run the "shell.run" command. It keeps giving me the error Menu:7: attempt to index ? (a nil value)

I have literally no clue why it is doing this when the syntax is correct. Here is the code:

Main Script
Spoiler/Testing.lua

local function main()

os.loadAPI("PantherR/APIs/Draw")
os.loadAPI("PantherR/APIs/Menu")
os.loadAPI("PantherR/APIs/Buttons")
os.loadAPI("PantherR/APIs/Config")
os.loadAPI("PantherR/APIs/Dropdown")

local currentMenu = 0
local doRedraw = false

local buttonsT = {
{
startX = 2,
startY = 3,
endX = 4,
endY = 5,
run = function() print("Hello!") end
}
}

local items = {
"One",
"Two",
"Three",
"Four",
"Five",
}

local function draw()

term.setBackgroundColor(colors.white)
term.clear()

Draw.barDraw(buttonsT,currentMenu)
Dropdown.dropdown(2,10,items,"Three",buttonsT)

end

local function buttons()
Buttons.initializeButtons(buttonsT)
end

local function loops()

while true do
os.pullEvent()
if doRedraw == true then
draw()
doRedraw = false
end
end

end

draw()

Menu.initalize(buttonsT, currentMenu, doRedraw, shell.getRunningProgram())

parallel.waitForAll(buttons,loops)

end

local ok, err = pcall(main)

if not ok then
sleep(0.1)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
print("PANTHER - FATAL ERROR")
print("App: "..shell.getRunningProgram())
print("Error: "..err)
print("Please report this error on the Github repository")
print("Press key to reboot...")
os.pullEvent("key")
os.reboot()
end

API
Spoiler/Panther/APIs/Menu

local x, y = term.getSize()
os.loadAPI("PantherR/APIs/Config")
local color = Config.readCfg(1)

local function restartProg(runner)
print(runner)
shell.run("shell")
end

function initalize(buttonsT, currentMenu, doRedraw, runner)
table.insert(buttonsT,{
startX=13,
startY=2,
endX=13,
endY=2,
depends = currentMenu == 1,
run = function() restartProg(runner) end,
})
end

function drawButton(x,y,padding,height,text,textColor,backColor)
if textColor == nil then
textColor = colors.lightGray
end
if backColor == nil then
backColor = colors.gray
end
term.setCursorPos(x,y)
paintutils.drawFilledBox(x,y,x+padding+string.len(text),y+height-1,backColor)
term.setCursorPos(x+padding,y+math.floor(height/2))
term.setTextColor(textColor)
write(text)
end
function drawSidebar()
if currentMenu == 0 then
currentMenu = 1
end
paintutils.drawFilledBox(1,1,14,y,tonumber(color))
term.setCursorPos(2,2)
term.setTextColor(colors.gray)
write("Menu")
drawButton(2,4,2,3,"Settings ")
drawButton(2,8,2,3,"Programs ")
drawButton(2,y-3,2,3," Reboot  ")
drawButton(2,y-7,2,3,"Shutdown ")
term.setTextColor(colors.red)
drawButton(13,2,0,0,"\7",colors.red,colors.white)
drawButton(6,2,2,0,"Home")
return 1
end

Any help would be appreciated!
EveryOS #2
Posted 23 May 2018 - 06:23 PM
Try this:

_G["shell"] = shell
add that as the first line of your main file

I personally do not really like the shell.run and os.loadAPI
Instead, I recommend using loadfile
Edited on 23 May 2018 - 04:24 PM
MarcoPolo0306 #3
Posted 23 May 2018 - 06:24 PM
Try this:

_G["shell"] = shell
add that as the first line of your main file

I personally do not really like the shell.run and os.loadAPI
Instead, I recommend using loadfile

Yep, it worked! Thanks!