settings (API)

From ComputerCraft Wiki
Revision as of 22:12, 15 January 2016 by MKlegoman357 (Talk | contribs) (Created page with "{{lowercase}} The '''settings API''' allows to store values and save them to a file for persistent configurations for your and CraftOS programs. The default file for saving se...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The settings API allows to store values and save them to a file for persistent configurations for your and CraftOS programs. The default file for saving settings is .settings sitting in the root of the computer. Settings can also be changed and added to all computers through ComputerCraft.cfg's S:default_computer_settings value.

Grid disk.png  settings (API)
Function Return values Description
settings.set(string name, any value) nil Sets the setting name to value.
settings.get(string name [, any default]) any value Returns the setting's name value, or default if the setting does not exist.
settings.unset(string name) nil Removes the setting name.
settings.clear() nil Removes all settings.
settings.getNames() table settingNames Returns a numerically-indexed table of all the setting's names.
settings.load(string path) boolean loaded Loads settings from a file.
settings.save(string path) boolean saved Saves current settings to a file.

Notes

Default Settings

These are the default settings of a computer (as seen in CC 1.77)

{
  [ "bios.use_multishell" ] = true,
  [ "shell.autocomplete" ] = true,
  [ "shell.allow_disk_startup" ] = false,
  [ "shell.allow_startup" ] = true,
  [ "lua.autocomplete" ] = true,
  [ "list.show_hidden" ] = false,
  [ "edit.autocomplete" ] = true,
}
  • shell.autocomplete - enables auto-completion in the Shell.
  • lua.autocomplete - enables auto-completion in the Lua program.
  • edit.autocomplete - enables auto-completion in the Edit program.
  • bios.use_multishell - enables Multishell on Advanced Computers, Turtles, Pocket Computers and Command Computers.
  • shell.allow_disk_startup - if a Disk Drive with a Disk inside that has a 'startup' script is attached to a computer, this setting allows to automatically run that script when the computer starts.
  • shell.allow_startup - if there is a 'startup' script in a computer's root, this setting allow to automatically run that script when the computer runs.
  • list.show_hidden - determines, whether the List program will list hidden files or not.

ComputerCraft.cfg

You can change or add default settings for all computers through ComputerCraft.cfg. The format is as follows:

  • each setting is separated by a comma (,)
  • setting's name and value is separated by an equals sign (=)

This example will disable auto-completion features in the default programs.

S:default_computer_settings=shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false