Advertisement
Guest User

items

a guest
Feb 20th, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. --This API handles items.
  2. --Please enter your config directory below
  3. configDirectory = '/config/itemLibrary.dat'
  4.  
  5. function main()
  6.   checkFile()
  7.   add('bananas')
  8.   local arr2 = retrieve()
  9.   print(arr2[1])
  10. end
  11.  
  12. function checkFile()
  13.   if not fs.exists(configDirectory) then
  14.     file = fs.open(configDirectory,'w')
  15.     file.close()
  16.   end
  17. end
  18.  
  19. function retrieve()
  20.   file = fs.open(configDirectory,'r')
  21.   local data = file.readAll()
  22.   file.close()
  23.   return textutils.unserialize(data)
  24. end
  25.  
  26. function put(x)
  27.   local file = fs.open(configDirectory,'w')
  28.   file.write(textutils.serialize(x))
  29.   file.close()
  30. end
  31.  
  32. function add(x)
  33.   local arr = retrieve()
  34.   arr[#arr+1] = x
  35.   put(arr)
  36. end
  37.  
  38.  
  39.  
  40. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement