This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
jelto365's profile picture

Program crashes when I leave the Age

Started by jelto365, 13 August 2014 - 01:19 PM
jelto365 #1
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/dAdxrpxr

Jelto365
Lyqyd #2
Posted 13 August 2014 - 03:32 PM
Check if data exists before attempting to index it.
jelto365 #3
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
Bomb Bloke #4
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.
jelto365 #5
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")
Bomb Bloke #6
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.
jelto365 #7
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 :)/>