From a5a1c606d41c5bfabe74a63f5c8d2d1090015c08 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Mon, 1 Jul 2019 11:58:56 -0400 Subject: [PATCH] add some more Lua tips --- webapp/views/pages/modding.ejs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/webapp/views/pages/modding.ejs b/webapp/views/pages/modding.ejs index 353e066..87e5ee8 100644 --- a/webapp/views/pages/modding.ejs +++ b/webapp/views/pages/modding.ejs @@ -160,16 +160,17 @@ help you get started: obj.do_something. This is helpful for functions used as object methods, which make use of the self variable. +
  • 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: things = {"something", "something else"}.
  • # is the length operator. if #minetest.find_nodes_in_area(pos0, pos1, "group:flora") > 3 then is legitimate code: it will cause the case to happen if the count of flora nodes in the 3D box is greater than 3.
  • -
  • Though lua guides will tell you there is no ternary operator, +
  • Though Lua guides will tell you there is no ternary operator, and that is technically true, you can do a ternary operation as follows: local gender = texture_name:find("_female") and "female" or "male" The code sets gender to either "female" or "male".
  • -
  • 0 is true in lua, but nil is false. This behavior is helpful when checking whether a setting is present: +
  • 0 is true in Lua, but nil is false. This behavior is helpful when checking whether a setting is present: local radius = (tonumber(minetest.setting_get("protector_radius")) or 5) The code allows a zero value.
  • Lua's tostring method does not have an underscore, and is a global function
  • @@ -177,6 +178,8 @@ help you get started: 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 serializeable" error +
  • For-loops use a "do" keyword: for i=-5, 5 do
  • +
  • Clauses (such as if, else and for) end with end
  • Minetest Lua functions unrelated to the engine's functionality: