Skip to content

mwseMCMTableVariable⚓︎

A TableVariable takes a lua table and stores the variable in the id field in that table.

The TableVariable can be used to save multiple changes to a config file only when the menu is closed. Load the config file with mwse.loadConfig(), pass it to any TableVariables in your MCM, and then save it using the template:saveOnClose() function.

This type inherits the following: mwseMCMVariable

Properties⚓︎

class⚓︎

The type of the variable.

Returns:

  • result (string)

componentType⚓︎

The type of this component.

Returns:

  • result ("Variable")

converter⚓︎

This function is called when the value of the variable is changed. The function can modify the new value before it is stored.

Returns:

  • result (fun(newValue): unknown)

defaultSetting⚓︎

If id does not exist in the table, it will be initialised to this value.

Returns:

  • result (unknown)

id⚓︎

Key in the config file used to store the variable.

Returns:

  • result (string, number)

inGameOnly⚓︎

If true, the setting containing this variable will be disabled while the game is on main menu.

Returns:

  • result (boolean)

restartRequired⚓︎

If true, updating the setting containing this variable will notify the player to restart the game.

Returns:

  • result (boolean)

restartRequiredMessage⚓︎

The default text is a localized version of: "The game must be restarted before this change will come into effect.".

Returns:

  • result (string)

table⚓︎

The table to save the data to.

Returns:

  • result (table)

value⚓︎

The value stored in the variable.

Returns:

  • result (unknown)

Methods⚓︎

get⚓︎

Returns the value stored in the variable.

local value = myObject:get()

Returns:

  • value (unknown)

new⚓︎

Creates a new variable of this type.

local variable = myObject:new({ id = ..., table = ..., defaultSetting = ..., inGameOnly = ..., restartRequired = ..., restartRequiredMessage = ..., converter = ... })

Parameters:

  • variable (table)
    • id (string, number): Key in the config file used to store the variable.
    • table (table): The table to save the data to.
    • defaultSetting (unknown): Optional. If id does not exist in the table, it will be initialised to this value.
    • inGameOnly (boolean): Default: false. If true, the setting containing this variable will be disabled if the game is on main menu.
    • restartRequired (boolean): Default: false. If true, updating the setting containing this variable will notify the player to restart the game.
    • restartRequiredMessage (string): Optional. The default text is a localized version of: "The game must be restarted before this change will come into effect.".
    • converter (fun(newValue): unknown): Optional. This function is called when the value of the variable is changed. The function can modify the new value before it is saved.

Returns:


set⚓︎

Changes the value stored in the variable. Calls the converter function with the new value before saving.

myObject:set(newValue)

Parameters:

  • newValue (unknown)