Jump to content




Saving Variables


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

#1 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 15 July 2012 - 03:56 PM

How do I save a variable without using a custom api? I want to have my lock program preserve what side the redstone output is on when the world resets, but I cannot figure out how to go about it.

#2 1lann

  • Members
  • 516 posts
  • LocationSeattle

Posted 15 July 2012 - 04:08 PM

You could try writing the variables to a file
local function save(data) 
  f = io.open("rsData", "w")
  f:write(tostring(data))
  f:close()
end

local function load()
  f = io.open("rsData", "r")
  rData = f:read("*l")
  if rData == "true" then
    return true
  elseif rData == "false" then
    return false
  else
    return nil
end


#3 Ponder

  • New Members
  • 49 posts

Posted 15 July 2012 - 04:43 PM

The standard textutils API has a serialize and a unserialize function, which can turn tables into text and vice versa. For a quick solution you could just put whatever you need to store inside a table, serialize and write it to a file.

#4 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 15 July 2012 - 04:47 PM

Thank you for your help; I have fixed it up accordingly.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users