G2A Many GEOs
SHARE
TWEET

set.lua

a guest Apr 6th, 2020 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. local tArgs = { ... }
  3. if #tArgs == 0 then
  4.     -- "set"
  5.     local _, y = term.getCursorPos()
  6.     local tSettings = {}
  7.     for n, sName in ipairs( settings.getNames() ) do
  8.         tSettings[n] = textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName))
  9.     end
  10.     textutils.pagedPrint(table.concat(tSettings, "\n"), y - 3)
  11.  
  12. elseif #tArgs == 1 then
  13.     -- "set foo"
  14.     local sName = tArgs[1]
  15.     print( textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) )
  16.  
  17. else
  18.     -- "set foo bar"
  19.     local sName = tArgs[1]
  20.     local sValue = tArgs[2]
  21.     local value
  22.     if sValue == "true" then
  23.         value = true
  24.     elseif sValue == "false" then
  25.         value = false
  26.     elseif sValue == "nil" then
  27.         value = nil
  28.     elseif tonumber(sValue) then
  29.         value = tonumber(sValue)
  30.     else
  31.         value = sValue
  32.     end
  33.  
  34.     local oldValue = settings.get( sValue )
  35.     if value ~= nil then
  36.         settings.set( sName, value )
  37.         print( textutils.serialize(sName) .. " set to " .. textutils.serialize(value) )
  38.     else
  39.         settings.unset( sName )
  40.         print( textutils.serialize(sName) .. " unset" )
  41.     end
  42.     if value ~= oldValue then
  43.         settings.save( ".settings" )
  44.     end
  45. end
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top