6 posts
Location
Holland
Posted 13 August 2014 - 03:19 PM
Hello,
I created a door that opens with a sensor from openperipherals.
The door stands in a mystcraft age and works perfectly.
But when I leave the age and come back the program crashes and gives this error:
door:15: attempt to index ? (a nill value)
The area is chunckloaded so can't be it.
Has anyone else got this problem to and is there a solution to it?
The pastebin of my code:
http://pastebin.com/dAdxrpxrJelto365
8543 posts
Posted 13 August 2014 - 03:32 PM
Check if data exists before attempting to index it.
6 posts
Location
Holland
Posted 14 August 2014 - 12:18 PM
That was the problem, every time I leave the computer is left without any data and crashes.
Is there a way to fix this? I tried checking again before asking for the data but that didn't seem to work
7083 posts
Location
Tasmania (AU)
Posted 14 August 2014 - 12:47 PM
Er, rather, Lyqyd's talking about the variable called "data". When you refer to "data.position", you're indexing into "data"'s table.
See, when your script starts, it does a sensor reading and sticks the detected player list into "players". It then never updates "players" again, so as soon as you move out of range of the sensor, your main loop tries to get specific info about users who are no longer anywhere near it - and this leads on to the crash when you try to work with that info.
So it looks like what you really want to do is replace line 10 with line 2. You'll also want to throw an extra sleep in so that your script pauses every time the loop repeats - I'd recommend at least two seconds.
6 posts
Location
Holland
Posted 14 August 2014 - 01:17 PM
It works now, Thanks
One problem still tough, when I relog the program starts but does'nt do anything. It even doesn't emit a redstone signal on the back
my startup program is:
shell.run("door")
7083 posts
Location
Tasmania (AU)
Posted 14 August 2014 - 03:25 PM
Try sticking a sleep(1) at the top of the script. Shouldn't be needed, but some versions of CC are a bit unreliable in some regards, and an early sleep is a silver bullet for certain issues.
6 posts
Location
Holland
Posted 14 August 2014 - 03:37 PM
It's fixed!
Thank you so much, I've spend hours on this script and sorting things out, it feels very good to see everything working now :)/>