-- We define the local variable for our settings table here so that our functions can see it
local settings

function script:init()
  settings = Util.optStorage(TheoTown.getStorage(), 'volcano_plugin:settings')

  -- Check if the the key is not set in the storage
  if settings.autoDisaster == nil then
    settings.autoDisaster = false
  end

  if settings.autoDisaster then
    TheoTown.setGlobalFunVar("!_autovolcanodisasterjajaja", 1)
  else
    TheoTown.setGlobalFunVar("!_autovolcanodisasterjajaja", 0)
  end
end

function script:settings()
  return {
    {
      name = 'Spawn Volcano Disaster',
      value = settings.autoDisaster,
      onChange = function(newState)
        settings.autoDisaster = newState
        if newState then
          TheoTown.setGlobalFunVar("!_autovolcanodisasterjajaja", 1)
        else
          TheoTown.setGlobalFunVar("!_autovolcanodisasterjajaja", 0)
        end
      end
    },
  }
end