@ -160,16 +160,17 @@ help you get started:
<code>obj.do_something</code>. This is helpful for functions used as
<code>obj.do_something</code>. This is helpful for functions used as
object methods, which make use of the <code>self</code>
object methods, which make use of the <code>self</code>
variable.</li>
variable.</li>
<li>Arrays start at 1 (unless you forcefully set a 0 or negative index). You must start the array at one for array functions to work. Prefilled arrays start at 1, and use curly braces: <code>things = {"something", "something else"}</code>.</li>
<li><code>#</code> is the length operator.
<li><code>#</code> is the length operator.
<code>if #minetest.find_nodes_in_area(pos0, pos1, "group:flora") > 3 then</code>
<code>if #minetest.find_nodes_in_area(pos0, pos1, "group:flora") > 3 then</code>
is legitimate code: it will cause the case to happen if the count of
is legitimate code: it will cause the case to happen if the count of
flora nodes in the 3D box is greater than 3.</li>
flora nodes in the 3D box is greater than 3.</li>
<li>Though l ua guides will tell you there is no ternary operator,
<li>Though L ua guides will tell you there is no ternary operator,
and that is technically true, you can do a ternary operation as
and that is technically true, you can do a ternary operation as
follows:
follows:
<code>local gender = texture_name:find("_female") and "female" or "male"</code>
<code>local gender = texture_name:find("_female") and "female" or "male"</code>
The code sets gender to either "female" or "male".</li>
The code sets gender to either "female" or "male".</li>
<li>0 is true in l ua, but nil is false. This behavior is helpful when checking whether a setting is present:
<li>0 is true in L ua, but nil is false. This behavior is helpful when checking whether a setting is present:
<code>local radius = (tonumber(minetest.setting_get("protector_radius")) or 5)</code>
<code>local radius = (tonumber(minetest.setting_get("protector_radius")) or 5)</code>
The code allows a zero value.</li>
The code allows a zero value.</li>
<li>Lua's tostring method does not have an underscore, and is a global function</li>
<li>Lua's tostring method does not have an underscore, and is a global function</li>
@ -177,6 +178,8 @@ help you get started:
an example, see owner of arrow projectile object in mobs redo), but
an example, see owner of arrow projectile object in mobs redo), but
trying to append an object to a string will result in a fatal "not
trying to append an object to a string will result in a fatal "not
serializeable" error</li>
serializeable" error</li>
<li>For-loops use a "do" keyword: <code>for i=-5, 5 do</code></li>
<li>Clauses (such as if, else and for) end with <code>end</code></li>
</ul>
</ul>
Minetest Lua functions unrelated to the engine's functionality:
Minetest Lua functions unrelated to the engine's functionality:
<ul>
<ul>