Page 1 of 1

Questions about lua API

PostPosted: Sun Oct 19, 2014 01:52
by Hashlime
Hi everyone, I started modding a few days ago and here is a list of questions I have :
  1. How can I add my new item to an existing group ? Ex: I add a 'Wood Planks' item how can I add it to 'group:wood' ?
  2. Is there a way to interact with the keyboard ?
  3. Is it possible to rewrite the 'Esc' menu ? (I didn't find anything in the code, is it defined in c++ while all others (menus) are defined in lua ?)
  4. Why some items are defined like this (I saw 'air' and 'ignored') :
    Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
    Code: Select all
    -- {...} = some stuff
    minetest.register_craftitem("air", {...})
  5. How the dependencies are managed ? If my mod's dependencies are not resolved what will happen ? What about priorities ? The dependencies are executed before/after/no relation ?
  6. If I add resources (textures, sound, models) to my mod are they overwritten by textures packs ?
  7. Is it possible to rotate (x, y, z axes) a Node box in Node Boxes ?
And another question about shaders : Can I code new shaders and place them in ~/.minetest (on Linux, I don't know the path on Windows/Mac OS) ?

Thank you.

Re: Questions about lua API

PostPosted: Sun Oct 19, 2014 03:30
by kaeza
Hello, and welcome.

1: You need to specify the group in the node `groups` field:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_node("foo:bar", {
  -- ...
  groups = { cracky=1, wood=1, foo=4, bar=2 },
  -- ...
})


2: Not currently, other than reading the game keys (up, down, left, right, jump, etc) via `playerobj:get_player_control()`.

4: I'm not sure what you mean.

5: The dependencies are loaded first, recursively. I.e. foo depends on bar and bleh, it loads bar first, then bleh, but bar depends on baz and bleh, so it loads baz first, then goes to bleh (from bar dependencies), then actually loads bar, then finally loads foo (the first mod). The `bleh` dependency of foo is ignored because it was already loaded before baz. If any mod in the chain is not found, the engine reports an error and refuses to start. *

6: Yes, but only textures AFAIK. Not sure if texture/resource packs can specify models/sounds.
7: Not currently.

Edit:
* To clarify on point 5, there's also optional dependencies, specified as 'modname?' in `depends.txt`. If the mod is not found, the engine just ignores it and continues with dependency checking.

Hope that helps.

Re: Questions about lua API

PostPosted: Sun Oct 19, 2014 15:38
by Hashlime
Thank you very helpful !
One more question about groups, in your example you wrote `wood=1`, what is the meaning of '1' ?

Re: Questions about lua API

PostPosted: Sun Oct 19, 2014 16:29
by Calinou
Hashlime wrote:Thank you very helpful !
One more question about groups, in your example you wrote `wood=1`, what is the meaning of '1' ?


It means the node is part of the “wood” group. Any integer value (even negative) can be used, even 100, but some groups actually only use 0 or 1 as values.

Re: Questions about lua API

PostPosted: Wed Oct 22, 2014 19:15
by Wuzzy
Is it possible to rewrite the 'Esc' menu ? (I didn't find anything in the code, is it defined in c++ while all others (menus) are defined in lua ?)

Of course it is! Minetest is free software. :-)

But it is defined in C++, not Lua. A few other menus are currently hardcoded in C++ as well, but not many.

Re: Questions about lua API

PostPosted: Sat Oct 25, 2014 11:14
by DuDraig
Hashlime wrote:Why some items are defined like this (I saw 'air' and 'ignored') :
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- {...} = some stuff
minetest.register_craftitem("air", {...})

The world is divided into areas that are not all necessarily loaded. There is a caching system that keeps areas and all the nodes in them from being loaded if they are not yet seen or used by players. The "ignore" node type means the area for that position is not loaded.

There is no such thing as an empty node position. It is always filled with something be it an item, an entity, a fluid, or air. This allows the world to deal with the effects of each type of node be it solid, liquid, or gas.

Re: Questions about lua API

PostPosted: Sat Oct 25, 2014 17:49
by rubenwardy
The don't have a mod name as they are in builtin, which is not a mod.