Posted 17 June 2014 - 02:18 AM
Okay, well… I know the title is a bit confusing in itself, but really, it is the best that I can describe the issue I'm having. I'm working on something that loosely resembles a button API (Which I may just try to learn how to make). Basically, I'm trying to have icons displayed, x and y coordinates stored in a table, and then use those coordinates to detect if a user clicks on the icons. When they click on the icons, an app is opened (the app's name is stored in the same table as the coordinates). I know, it sounds confusing…and, truthfully, it is. Most likely, I'll just use a button API that already made (or look at more tutorials on how to make one), but I wanted to use what I know already to try this… and, unfortunately, it seems that I've failed :mellow:/> . But, in any case, I'd like to know what I'm doing incorrectly, if anything, or if it's just not possible to do what I want with the setup I have here.
The error I'm getting is:
[string "test"]:46: attempt to index a nil value
On line 46, I have:
if x >= appsTable[1] and x < appsTable[2] and y >= appsTable[3] and y < appsTable[4] then
All I want to know is what exactly the nil value is (Really, I'm confused). I've tried everything I can, but just can't seem to get it to work. I'd greatly appreciate any help that all of you can give. Sorry if this is too confusing… I don't really know how to explain it any better :/ Anyways, thanks for you help!
- Nin
The error I'm getting is:
[string "test"]:46: attempt to index a nil value
On line 46, I have:
if x >= appsTable[1] and x < appsTable[2] and y >= appsTable[3] and y < appsTable[4] then
appsTable = {}
aTn = 1
function UIBlockAdvanced(animatesetting,startposx,endposx,startposy,endposy,Bg,tablevalue)
if animatesetting == "animate" then
aTn = aTn + 1
table.insert(appsTable,aTn,tablevalue)
u = startposy
repeat
c = startposx
repeat
term.setBackgroundColor(Bg)
term.setCursorPos(c,u)
term.write(" ")
c = c+1
until c == endposx
sleep(0.00)
u = u + 1
until u == endposy
elseif animatesetting == "normal" then
aTn = aTn + 1
table.insert(appsTable,aTn,tablevalue)
u = startposy
repeat
c = startposx
repeat
term.setBackgroundColor(Bg)
term.setCursorPos(c,u)
term.write(" ")
c = c+1
until c == endposx
u = u + 1
until u == endposy
end
end
function findPoint()
for i = 1,aTn do
event, button, x, y = os.pullEvent("mouse_click")
if x >= appsTable[i][1] and x < appsTable[i][2] and y >= appsTable[i][3] and y < appsTable[i][4] then
shell.run(appsTable[i][5])
aTn = 1
end
end
end
local function drawDesktop()
term.setBackgroundColor(userBg)
term.clear()
term.setBackgroundColor(userNotification)
term.setCursorPos(1,h)
term.clearLine()
term.setCursorPos(1,h-1)
term.clearLine()
UIBlock("normal",1,4,h-1,h+1,userTc)
term.setBackgroundColor(userBg)
term.setCursorPos(2,h)
term.write(" ")
m = 2
z = 6
y = 2
l = 5
o = 1
e = 1
newY = 2
newL = 5
for _, file in ipairs(fs.list("core")) do
if o > 13 then
o = 1
end
if e > 16 then
m = 22
z = 26
UIBlockAdvanced("normal",m,z,y,l,colorTable[o],{m,z,y,l,"core/"..file})
y = y + 4
l = l + 4
o = o + 1
e = e + 1
newY = 2
newL = 5
elseif e > 12 then
m = 17
z = 21
UIBlockAdvanced("normal",m,z,newY,newL,colorTable[o],{m,z,newY,newL,"core/"..file})
newY = newY + 4
newL = newL + 4
o = o + 1
e = e + 1
y = 2
l = 5
elseif e > 8 then
m = 12
z = 16
UIBlockAdvanced("normal",m,z,y,l,colorTable[o],{m,z,y,l,"core/"..file})
y = y + 4
l = l + 4
o = o + 1
e = e + 1
newY = 2
newL = 5
elseif e > 4 then
m = 7
z = 11
UIBlockAdvanced("normal",m,z,newY,newL,colorTable[o],{m,z,newY,newL,"core/"..file})
newY = newY + 4
newL = newL + 4
y = 2
l = 5
o = o + 1
e = e + 1
else
UIBlockAdvanced("normal",m,z,y,l,colorTable[o],{m,z,y,l,"core/"..file})
y = y + 4
l = l + 4
o = o + 1
e = e + 1
end
end
end
local function desktopListen()
while true do
event, button, x, y =os.pullEvent("mouse_click")
if x == nil or y == nil then
cPrint("What")
end
if x>0 and x<4 and y>h-2 and y<h+1 then
break
else
findPoint()
appsList = {}
drawDesktop()
end
end
end
drawDesktop()
desktopListen()
All I want to know is what exactly the nil value is (Really, I'm confused). I've tried everything I can, but just can't seem to get it to work. I'd greatly appreciate any help that all of you can give. Sorry if this is too confusing… I don't really know how to explain it any better :/ Anyways, thanks for you help!
- Nin