hello everyone,
I have a question about cc, i'm not good at it but i'm trying to learn it.
I'm making a program to automatically open the door of my house ( castle ) if a player approaches.
I use a sensor at the left side of the advanced computer and the redstone output is at the back of the computer
this is the code I wrote and the error it gave.
Can someone help me?
os.loadAPI("sensor")
prox = sensor("left")
while true do
t = prox.getTargets(name)
if t == "aisha_girl_15" then
rs.setOutput("back",true)
wait(15)
rs.setOutput("back",false)
else
wait(5)
end
end
and the error it gave:
file not found:
doorway:2: attempt to index ? ( a nill value)
3 replies to this topic
#1
Posted 04 April 2014 - 07:53 AM
#2
Posted 04 April 2014 - 02:45 PM
Moved to Ask A Pro.
Make sure you're posting questions in the right area. Your questions get more exposure in this section, so that we can help you easier.
Make sure you're posting questions in the right area. Your questions get more exposure in this section, so that we can help you easier.
#3
Posted 04 April 2014 - 03:10 PM
Like the error says, this
The proper code would be
This also won't work
Regardless, the result of getTargets() is not a string, so this won't work
prox = sensor("left")
Is not valid. Where did you pick this up?The proper code would be
local prox = peripheral.wrap"left"
This also won't work
t = prox.getTargets(name)That name variable is listed there for a reason, not because it expects a variable called name. Although i don't believe the getTargets function uses any arguments at all.
Regardless, the result of getTargets() is not a string, so this won't work
if t == "aisha_girl_15" thenIt returns a numerically indexed table, meaning you'll have to loop through it looking for the desired name
for i=1,#t do --loop once for every key in the table t
if t[i] == "aisha_girl_15" then --compare the value stored in the table as the current loopCount
--open door here
break --end loop
end
end
I haven't worked with the sensor in ages, but chances are the actual player name is stored inside another table that's stored in the numerical key. Probably something liket[i].playerName
#4
Posted 04 April 2014 - 04:15 PM
first i will move it to the proper forum...
and thank you for the answer, i will test it out.
for that part of code...
i found that code on internet
and thank you for the answer, i will test it out.
for that part of code...
i found that code on internet
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











