ToJSON: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
Line 2: | Line 2: | ||
{{Server function}} | {{Server function}} | ||
This function converts one or more variables into a [[JSON]] encoded string. You can use this to store the data and then load it again using [[fromJSON]]. | This function converts one or more variables into a [[JSON]] encoded string. You can use this to store the data and then load it again using [[fromJSON]]. | ||
{{New feature|3| | {{New feature|3|1.0| | ||
DP2 ignores the first argument, it starts generating the JSON string from the second argument and onwards. This is fixed in DP3 and might cause compatibility problems in scripts using this function. | DP2 ignores the first argument, it starts generating the JSON string from the second argument and onwards. This is fixed in DP3 and might cause compatibility problems in scripts using this function. | ||
}} | }} |
Revision as of 01:13, 25 November 2008
This function converts one or more variables into a JSON encoded string. You can use this to store the data and then load it again using fromJSON. DP2 ignores the first argument, it starts generating the JSON string from the second argument and onwards. This is fixed in DP3 and might cause compatibility problems in scripts using this function.
Syntax
string toJSON( var arguments ... )
Required Arguments
- arguments: A list of arguments of any type. Arguments that are elements will be stored as element IDs that are liable to change between sessions. As such, do not save elements across sessions as you will get unpredictable results.
Returns
Returns a JSON formatted string.
Example
This example shows how you can encode an array. The string json should equal "["cat", "mouse", {cat:"hungry",mouse:"food"}]" after executed.
local json = toJSON ( "cat", "mouse", {cat="hungry",mouse="food"} )
See Also
- getMaxPlayers
- getServerConfigSetting
- getServerHttpPort
- getServerName
- getServerPassword
- getServerPort
- isGlitchEnabled
- setGlitchEnabled
- setMaxPlayers
- setServerConfigSetting
- setServerPassword
- shutdown