Get: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(modified bad code)
 
(12 intermediate revisions by 9 users not shown)
Line 2: Line 2:
__NOTOC__
__NOTOC__
This function gets a setting's value, or a group of settings' values, from the [[settings system|settings registry]].
This function gets a setting's value, or a group of settings' values, from the [[settings system|settings registry]].
{{Note|Your settings cannot have a period (.) in them. This character is reserved. Read below for more details.}}


==Syntax==  
==Syntax==  
Line 9: Line 10:


==Optional Arguments==
==Optional Arguments==
'''settingName:''' The name of the setting you want to set. See [[settings system#Setting names|setting names]] for information on settings names.
'''settingName:''' The name of the setting you want to get. See [[settings system#Setting names|setting names]] for information on settings names.


===Returns===
===Returns===
Returns a ''table'' (in associative-array form) containing:
Returns the value of the setting if a single setting was specified and found, or a ''table'' (in associative-array form) containing:
*the list of global setting name/value pairs if "." is passed as a setting name,
*the list of global setting name/value pairs if "." is passed as a setting name,
*the list of resource settings if a resource name followed by a "." is passed,
*the list of resource settings if a resource name followed by a "." is passed,
*the list of the script's resource settings if an empty string is passed.
*the list of the script's resource settings if an empty string is passed.
It returns ''false'' if the specified setting doesn't exist.
It returns ''false'' if the specified setting or settings group doesn't exist, or if the settings group you are trying to retrieve doesn't have any public or protected settings.


==Example==
==Example==
No example yet.
Example returns a value from the settings registry with the name "respawnTime".
<syntaxhighlight lang="lua">
function getMySetting()
    if get ( "respawnTime" ) then
        return get ( "respawnTime" )
    end
    return false
end
</syntaxhighlight>
Or easier:
<syntaxhighlight lang="lua">
mySetting=get("respawnTime") or false
</syntaxhighlight>


==See Also==
==See Also==
{{Settings registry functions}}
{{Settings registry functions}}


[[Category:Needs Example]]
[[ru:get]]

Latest revision as of 18:14, 26 August 2019

This function gets a setting's value, or a group of settings' values, from the settings registry.

[[{{{image}}}|link=|]] Note: Your settings cannot have a period (.) in them. This character is reserved. Read below for more details.

Syntax

var get ( string settingName )

Optional Arguments

settingName: The name of the setting you want to get. See setting names for information on settings names.

Returns

Returns the value of the setting if a single setting was specified and found, or a table (in associative-array form) containing:

  • the list of global setting name/value pairs if "." is passed as a setting name,
  • the list of resource settings if a resource name followed by a "." is passed,
  • the list of the script's resource settings if an empty string is passed.

It returns false if the specified setting or settings group doesn't exist, or if the settings group you are trying to retrieve doesn't have any public or protected settings.

Example

Example returns a value from the settings registry with the name "respawnTime".

function getMySetting()
    if get ( "respawnTime" ) then
        return get ( "respawnTime" )
    end
    return false
end

Or easier:

mySetting=get("respawnTime") or false

See Also