Creeper9207

database api

Feb 18th, 2015
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. --Creeper9207 Code: database (API)--
  2. --setValue(database file, key, value)
  3. --getValue(database file, key)
  4. function setValue(database, key, value)
  5. tonumber(key)
  6. uFile = fs.open(database, "r")
  7. lFile = uFile.readAll()
  8. uFile.close()
  9. local tFile = fs.open(database, "w")
  10. tDB = textutils.unserialize(lFile)
  11. table.insert(tDB, key, value)
  12. tFile.write(textutils.serialize(tDB))
  13. tFile.flush()
  14. tFile.close()
  15. end
  16. function getValue(tDatabase, tKey)
  17. tonumber(tKey)
  18. local tFile = fs.open(tDatabase, "r")
  19. local tData = tFile.readAll()
  20. tRealData = textutils.unserialize(tData)
  21. local value = tRealData[tKey]
  22. tFile.close()
  23. return value
  24. end
Advertisement
Add Comment
Please, Sign In to add comment