Posted 05 October 2013 - 05:16 PM
Title: Weird Problem With Functions!
K so I am making a OS(kinda'of, much more like a launcher) and I encountered one big annoying problem…
So I have this function
But the func() gives me "attempt to call nil"
If I replace it with
Note: If I move the shell.run or func() sequence outside this function they will work…
So, to use the function I would do:
icons.ini:
Could somebody help me? I would have posted the whole script, but it has an entire army of configurations behind it…
Here you go anyway: Pastebin Link
K so I am making a OS(kinda'of, much more like a launcher) and I encountered one big annoying problem…
So I have this function
function MID(buttons,click,clickX, clickY)
for k,button in ipairs(buttons) do
term.setCursorPos(45,10)
for x=button[1],button[2] do
term.setCursorPos(45,11)
if x==clickX then
term.setCursorPos(45,12)
for y=button[3],button[4] do
term.setCursorPos(45,13)
if y==clickY then
if click==1 then
local func = loadstring("/data/settings/PROGRAMS/RadOS.lua")
setfenv(func, getfenv(1))
func()
end
end
end
end
end
end
end
But the func() gives me "attempt to call nil"
If I replace it with
shell.run("/data/settings/PROGRAMS/RadOS.lua")
it will give me "Attempt to index ? (a nil value)Note: If I move the shell.run or func() sequence outside this function they will work…
So, to use the function I would do:
DATAFOLDER="/data"
local _,click,clickX,clickY = os.pullEvent("mouse_click")
local buttons = readIniFile(DATAFOLDER.."/settings/MA/icons.ini")
MID(buttons,click,clickX,clickY)
icons.ini:
2.0|16.0|3.0|6.0|/data/settings/PROGRAMS/icon_softwareCenter|
19.0|33.0|3.0|6.0|/data/settings/PROGRAMS/icon_projector|
36.0|50.0|3.0|6.0|/data/settings/PROGRAMS/icon_console|
2.0|16.0|8.0|11.0|/data/settings/PROGRAMS/RadOS.lua|
Could somebody help me? I would have posted the whole script, but it has an entire army of configurations behind it…
Here you go anyway: Pastebin Link