Jump to content




Attempt to index ? (a nil value)


  • You cannot reply to this topic
2 replies to this topic

#1 Abahu

  • Members
  • 20 posts

Posted 23 December 2013 - 05:20 PM

Hi, I'm making a system that monitors turtles and their digging progress. I've implemented a mapping system and a system to take over a turtle at any given time. I've seem to run into a problem when I tried making a system to save and later load my map. Here's the snippet of code:

function save(f)
if fs.exists("mine/map" .. tostring(f)) then fs.delete("mine/map" .. tostring(f)) end
local file = fs.open("mine/map" .. tostring(f), "w")
file.write(textutils.serialize(_G["a" .. tostring(f)]))
file.close()
end
function load(f)
local file = fs.open("mine/map" .. tostring(f), "r")
local data = file.readAll()
file.close()
return textutils.unserialize(data)
end

and the program returns the error message stated in the title at the line "file.write(textutils.serialize(_G["a" .. tostring(f)]))"
Why is this? How can I fix this?

#2 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 23 December 2013 - 06:13 PM

Have you read the sticky post entitled "Read this before asking questions"?

Also, I see that you are new here. Have you read any sticky posts, or the global announcement entitled "Forum Guidelines"?

EDIT: In addition, I would be more likely to take a detailed look at your code if it was indented.

EDIT 2: Also, can you post your whole code? It would be easier to debug. If you don't want to post it, you can PM me it.

Edited by awsmazinggenius, 23 December 2013 - 06:31 PM.


#3 Abahu

  • Members
  • 20 posts

Posted 23 December 2013 - 07:51 PM

Sorry, I didn't read that >.< I should've, sorry. However, I don't know why this happens The code itself is quite long, but here you go:

Spoiler

EDIT: I fixed the problem with a new saving and loading format. I'm not saving the entire table, just the values that aren't 2.

Edited by Abahu, 24 December 2013 - 12:39 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users