local pie = ""
local x = ""
local y = ""
local t = {}
rednet.open("top")
function getDest()
g = fs.open("dest","r")
print(g.readAll())
g.close()
end
function setDest(x,y)
t[x] = {}
t[x][1] = y
end
function send()
print("destonation")
c = read()
if c == hi[c] then
sleep(1)
rednet.send(tonumber(t[c]["comp"]),"open")
sleep(1)
end
end
function rec(o)
if o == "open" then
redstone.setOutput("left",true)
sleep(2)
redstone.setOutput("left",false)
end
end
getDest()
setDest(x,y)
hi[x] = {}
hi[x][1] = y
sleep(1)
while true do
shell.run("clear")
a,b,c,d,e = os.pullEvent()
if a == "modem_message" then
rec(e)
elseif a == "key" then
send()
end
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
[Lua][Error]attempt to index(a nil value)
Started by jamzam90, 21 April 2013 - 07:53 PMPosted 21 April 2013 - 09:53 PM
error on line 21
Edited on 21 April 2013 - 08:49 PM
Posted 21 April 2013 - 09:59 PM
It expects that x is a variable. Put it into quotations and then it would be fine:
t['x'] = {}
t['x'] = {}
Posted 21 April 2013 - 10:00 PM
I think x is a variable, since its in the function… bad indentation… OP please use [code][/code] tags and re-indent the code so it is more readableIt expects that x is a variable. Put it into quotations and then it would be fine:
t['x'] = {}
Posted 21 April 2013 - 10:02 PM
It was Indented when i made it and copied the editor on here doesnt like tabsI think x is a variable, since its in the function… bad indentation… OP please use [code][/code] tags and re-indent the code so it is more readableIt expects that x is a variable. Put it into quotations and then it would be fine:
t['x'] = {}
Posted 21 April 2013 - 10:03 PM
@BIT:
Lol, didnt even saw it.. I should have looked better though…
@OP
Are you sure you are using the parameters?
Lol, didnt even saw it.. I should have looked better though…
@OP
Are you sure you are using the parameters?
Posted 21 April 2013 - 10:05 PM
Unless it is in code tags….It was Indented when i made it and copied the editor on here doesnt like tabs
now your line
setDest(x,y)
where are x and y meant to be coming from? because at the moment they are nil and that is causing your problemsPosted 21 April 2013 - 10:05 PM
As far as i can tell I am.@BIT:
Lol, didnt even saw it.. I should have looked better though…
@OP
Are you sure you are using the parameters?
Posted 21 April 2013 - 10:06 PM
Unless it is in code tags….It was Indented when i made it and copied the editor on here doesnt like tabs
now your linewhere are x and y meant to be coming from? because at the moment they are nil and that is causing your problemssetDest(x,y)
the x and y are coming from the getDest() function
Posted 21 April 2013 - 10:08 PM
- derping here
Well.. X abd y are never defined as variable.. Thats your problem
Well.. X abd y are never defined as variable.. Thats your problem
Posted 21 April 2013 - 10:18 PM
Changed the Main post
Edited on 21 April 2013 - 08:30 PM
Posted 21 April 2013 - 10:22 PM
does the file 'dest' exist on the computer?
I suggest this code
I suggest this code
function getDest()
local g = fs.open('dest', 'r')
if g then
print(g.readAll())
g.close()
else
-- the file doesn't exist, create it here and set all your values to defaults
end
end
Posted 21 April 2013 - 10:26 PM
the file dest does exist
Posted 21 April 2013 - 10:30 PM
then what line is the new error happening on?
Posted 21 April 2013 - 10:34 PM
its happening on line 21
Posted 21 April 2013 - 10:46 PM
@jamzam90:
You have to post your whole code or this is a guessing game and we can't help you properly.
You don't go to your doctor with only the foot that is hurting. You always take your whole body, don't you? ;)/>
You have to post your whole code or this is a guessing game and we can't help you properly.
You don't go to your doctor with only the foot that is hurting. You always take your whole body, don't you? ;)/>
Posted 21 April 2013 - 10:50 PM
I hadnt noticed some of it was missing@jamzam90:
You have to post your whole code or this is a guessing game and we can't help you properly.
You don't go to your doctor with only the foot that is hurting. You always take your whole body, don't you? ;)/>
Posted 21 April 2013 - 10:59 PM
Do what Engineer said, i.e. replace all t[x] with t["x"].
Ort as an alternative which works the same: replace it with t.x
Do this with all the tables (hi[x] -> h["x"] or h.x)
Edit - to explain a little as to why:
fruits[abc] will access the table fruits with the key in abc.
abc is a variable here, so whatever is in abc will be the key, not "abc".
If abc == "yummy", then fruits[abc] is the same as fruits["yummy"].
Also, to make it easier to access named keys, Lua allows to replace fruits["yummy"] with fruits.yummy
Ort as an alternative which works the same: replace it with t.x
Do this with all the tables (hi[x] -> h["x"] or h.x)
Edit - to explain a little as to why:
fruits[abc] will access the table fruits with the key in abc.
abc is a variable here, so whatever is in abc will be the key, not "abc".
If abc == "yummy", then fruits[abc] is the same as fruits["yummy"].
Also, to make it easier to access named keys, Lua allows to replace fruits["yummy"] with fruits.yummy
Edited on 21 April 2013 - 09:05 PM