Advertisement
CaptainSpaceCat

Updater

May 24th, 2017
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function update(var,value)
  2.   if not fs.exists("saveData") then
  3.     local h = fs.open("saveData", "w")
  4.     h.close()
  5.   end
  6.   if type(value) == "number" then
  7.     value = tostring(value)
  8.   elseif type(value) == "table" then
  9.     local v = "{"
  10.     for i = 1, #value-1 do
  11.       v = v .. tostring(value[i]) .. ","
  12.     end
  13.     v = v .. tostring(value[#value]) .. "}"
  14.     value = v
  15.   elseif type(value) == "string" then
  16.     value = "\""..value.."\""
  17.   end
  18.   local str = fs.open("saveData","r").readAll()
  19.   if str:find(var) then
  20.     str = str:gsub(var.."%=.-%;",var.."="..value..";")
  21.   else
  22.     str = str .."\n"..var.."="..value..";"
  23.   end
  24.   local h = fs.open("saveData","w")
  25.   h.write(str)
  26.   h.close()
  27. end
  28.  
  29. update("a", 1)
  30. update("b", "frog")
  31. update("c", 4)
  32. local test = {1, 2, 3}
  33. update("test", test)
Advertisement
RAW Paste Data Copied
Advertisement