Modding Tutorial Book (new: Code architecture, unit testing)

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Modding Tutorial Book (new: Code architecture, unit testing)

by rubenwardy » Post

It's register_on_joinplayer, and you're missing the function(player)

Code: Select all

minetest.register_on_joinplayer(function(player)
  local idx = player:hud_add({
      hud_elem_type = "text",
      position      = {x = 0.5, y = 0.5},
      offset        = {x = 0,   y = 0},
      text          = "Hello world!",
      alignment     = {x = 0, y = 0},  -- center aligned
      scale         = {x = 100, y = 100}, -- covered later
    })
end)
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
debiankaios
Member
Posts: 910
Joined: Thu Dec 03, 2020 12:48
IRC: debiankaios
In-game: debiankaios Nowe
Location: germany
Contact:

Re: Modding Tutorial Book (new: Code architecture, unit testing)

by debiankaios » Post

Now it work, thank you!

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Modding Tutorial Book (new: Code architecture, unit testing)

by sirrobzeroone » Post

Playing around with Aliases....what fun :)

Thank you very much for the alias chapter:
https://rubenwardy.com/minetest_modding ... em-aliases

Small feedback:
Would it be better if this example had local at the front and quotes were needed?

Code: Select all

itemname = minetest.registered_aliases[itemname] or itemname
to

Code: Select all

local itemname = minetest.registered_aliases["itemname"] or "itemname"
Was just concerned someone could follow along and end up with a heap of globals defined not to mention quoting around a variable/table name which would lead to some fun crashes.

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Modding Tutorial Book (new: Code architecture, unit testing)

by rubenwardy » Post

Hi, no that code is correct. itemname would be a variable

Code: Select all

local itemname = "dirt"

itemname = minetest.registered_aliases[itemname] or itemname
I'll update the book to include that local Def to make it clearer
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Slightly
Member
Posts: 37
Joined: Sun May 15, 2022 22:29
In-game: Slightly

Re: Modding Tutorial Book (new: Code architecture, unit testing)

by Slightly » Post

I am new to MT modding and I have been puzzling over this exact example in the book. I understand creating an alias, I think, and I have seen that in mods I am looking at, but the sentence "Mods need to make sure to resolve aliases before dealing directly with item names, as the engine won’t do this." tells me I need to do something important with this itemname = minetest.registered_aliases... but I can't tell when or where I must do it.

Is it used before the item name is needed, to check if there is an alias? An example of where might help.

The book is extremely helpful!

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Modding Tutorial Book (new: Code architecture, unit testing)

by sirrobzeroone » Post

I've been digging for info on ABM's a little more detailed than ABM == limit use. I'm not sure if some of the info Krock supplied when answering a question could be added to the ABM section or another section? I know it doesn't really fit the modding book but also doesn't fit the API info very well either. Sort of nice technical info to know when your tinkering around with ABM's or rather trying to avoiding using them or make an ABM process more efficient. I thought this was pretty interesting info and I can't think of any other way to try and save it so others can find it more easily.
Krock wrote:
Sat Nov 30, 2019 13:49

A few basics for understanding what's happening in the code (entire function).
1) There's some node caching, but the final effect is negligible (why? see below).
2) ABMHandler::apply is called for each active mapblock (next to players, usually)
3) Each node is checked whether it has ABMs assigned to it (3x for-loop)
4) Each ABM is run and checked for its probability (chance value) and neighbour nodes (3x3x3-1 checks)
5) If everything's fine, the Lua callback from the ABM definition is run

So in the worst case there are 1 + 3 + 1 + 3 loops that have to be executed each second. In a test world this takes ~60us to execute it each second. See F6 profiler "SEnv: modify in blocks avg per interval" (average value).

What likely matters here is the amount of code executed in the Lua callback.

Things that make ABMs faster (top = most effective)
  • Either use LBMs or node timers to replace ABMs (saves up to 8 loops)
  • Decrease active_block_range to 2 (saves 98 active mapblocks)
  • Increased "chance" or "interval" (saves up to 3 loops, skipped neighbour lookup)
  • Slim "action" callback Lua function (saves time for executed ABMs)
  • Less node replacements in Lua (saves client mapblock mesh creation time and server-side map saving)
[/list]

No, neither network nor client lag have an impact on ABM execution.

User avatar
debiankaios
Member
Posts: 910
Joined: Thu Dec 03, 2020 12:48
IRC: debiankaios
In-game: debiankaios Nowe
Location: germany
Contact:

Re: Modding Tutorial Book (new: Code architecture, unit testing)

by debiankaios » Post

Please merge the german translation of modding book. Thankyou!

User avatar
debiankaios
Member
Posts: 910
Joined: Thu Dec 03, 2020 12:48
IRC: debiankaios
In-game: debiankaios Nowe
Location: germany
Contact:

Re: Modding Tutorial Book (new: Code architecture, unit testing)

by debiankaios » Post

Good day rubenwardy,
the german translation is now rebased since 1 month, and up-to-day, but still waits without an answer for a merge. I would be happy about an answer (at least). Thankyou!

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 10 guests