Page 1 of 1

[SOLVED] First Mod - List all available nodes

PostPosted: Fri Sep 16, 2016 10:39
by MultiPlus
Hello everybody,

Today i make my first mod to test development MineTest. Il want to do a mod that lists all available nodes on game via mintetest.registered_nodes but it does not work...

I fallowed the exemples on this topic... https://forum.minetest.net/viewtopic.php?f=9&t=11294

List all :
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
   for key, value in pairs(minetest.registered_nodes) do
      minetest.debug("Node " .. key)       
   end

Nothing...

Or display count :
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.debug("Count " ..table.getn( minetest.registered_nodes))

Count 0


I do not have the lua file available, I send later.

Thx.

Re: First Mod - List all available nodes

PostPosted: Fri Sep 16, 2016 13:57
by Wuzzy
Please check the Lua API reference again.
Minetest.debug takes TWO arguments, the first one is for the message type, not the message itself.

Also, what's table.getn? I don't see it in the Lua documentation. I am surprised that it works in the first place. Did you maybe mean table.maxn? Well, check the Lua documentation again. It only shows the largest NUMERIC index. minetest.registered_nodes is indexed by itemstrings. There are no numeric indexes in this table, so the answer of this function is correct.

Note this function has been removed in later Lua versions (but not Lua 5.1), so I don't recommend to use it.

Re: First Mod - List all available nodes

PostPosted: Fri Sep 16, 2016 14:11
by MultiPlus
OK thank you for this information I look tonight.

Re: First Mod - List all available nodes

PostPosted: Fri Sep 16, 2016 17:26
by MultiPlus
Perfect, thanks for your help.

Re: First Mod - List all available nodes

PostPosted: Fri Sep 16, 2016 18:59
by kaeza
Wuzzy wrote:Also, what's table.getn? I don't see it in the Lua documentation.

IIRC, it's a function from 5.0, removed in 5.1. Its need was mostly replaced by the length operator (`#t`).