author nemo
Thu, 27 Jan 2022 17:26:11 -0500
changeset 2219 12e5f8732e54
parent 1375 e6e1f4a61b06
permissions -rw-r--r--
latest on 1.0.0 branch is better

#summary Lua library documentation of Params; for parameter handling
#labels !LuaLibrary
= Lua library: `Params` =
The Params library is a small library introduced in 0.9.21. It provides a function to parse the parameter string `ScriptParam` and it is intended to simplify using this string.

This library requires the parameter string to be in a certain format. It must be a comma-seperated list of kev-value pairs in the `key=value` format. Examples:

<code>health=100, ammo=5</code>
<code>param1=hello, param2=whatever, param3=5325.4</code>

Using this library is by no means neccessary, you could use practically whatever syntax you wish if you write your own code for parsing.

== `parseParams()` ==
Parses `ScriptParam` and writes the result into the global table `params`. The table will follow the `key=value` pattern. Both keys and pairs are stored as string.

=== Example  ===
<code language="lua">
function onParameters()
    if params["myparam1"] == "hello" then
        WriteLnToConsole("Hello World!")

If the key-value pair `myparam1=hello` is present, this script writes “Hello World!” in the console. All these inputs would trigger the event:

<code>myparam2=whatever, myparam1=hello</code>
<code>g=4, f=56, m=56, myparam1=hello</code>