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

User avatar
Lone_Wolf
Member
Posts: 2576
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: Modding Tutorial Book (new: Privileges)

by Lone_Wolf » Post

Could you add a part that shows you how to register a tool? Or is there and I missed it?
I'm having trouble understanding the highlighted text:
snappy={times={[1]=1.90, [2]=0.90, [3]=0.30}, uses=40, maxlevel=3},
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

User avatar
Napiophelios
Member
Posts: 1035
Joined: Mon Jul 07, 2014 01:14
GitHub: Napiophelios
IRC: Nappi
In-game: Nappi

Re: Modding Tutorial Book (new: Privileges)

by Napiophelios » Post

Lone_Wolf wrote:Could you add a part that shows you how to register a tool? Or is there and I missed it?
I'm having trouble understanding the highlighted text:
snappy={times={[1]=1.90, [2]=0.90, [3]=0.30}, uses=40, maxlevel=3},
Krock explains it pretty well here

User avatar
Lone_Wolf
Member
Posts: 2576
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: Modding Tutorial Book (new: Privileges)

by Lone_Wolf » Post

Where can i get ChatCmdBuilder?
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

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: BasicMapOps, AutoErrorChecki

by rubenwardy » Post

Two new chapters added:
Also made ChatCmdBuilder a bit less misleading, and added a short section on Lua patterns

Available to download in HTML or PDF form: https://github.com/rubenwardy/minetest_ ... g/20180225
The book is 110 pages when made into a standard paperback book!
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

hajo
Member
Posts: 606
Joined: Thu Oct 13, 2016 10:45
Location: DE
Contact:

Re: Modding Tutorial Book

by hajo » Post

rubenwardy wrote:Two new chapters added:
I had another look at your book, and noticed
* "Getting and Setting Privileges" - needs an explanation how to check if a player has an account
* Detached inventory - where are they stored, is there a sizelimit ?

Also:
* How about geany, to recommand as editor / IDE ?
* In the PDF, some headings should start on a new page, eg.
Mod Folder Structure, Overriding, Foods, Liquid, Map Structure-Reading, Writing Nodes,
Getting a Metadata Object, Setting Metadata, Admin complex command,
Displaying Formspecs, Inventory-More Methods, Adding to a List,
Github, or another VCS

KCoombes
Member
Posts: 427
Joined: Thu Jun 11, 2015 23:19
In-game: Knatt
Location: SW Florida, USA

Re: Modding Tutorial Book (new: BasicMapOps, AutoErrorChecki

by KCoombes » Post

Most excellent resource! Any chance of updating the downloadable examples file?

User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

WHY?

by Wuzzy » Post

Why is this still not in official?
WHYYYYYY?

User avatar
MineYoshi
Member
Posts: 5373
Joined: Wed Jul 08, 2015 13:20
Contact:

Re: Modding Tutorial Book (new: BasicMapOps, AutoErrorChecki

by MineYoshi » Post

Hi, Rubenwardy. Recently I got illuminated while eating a piece of chicken and I got the idea of translating your modding tutorial to Spanish. Do you allow me to do so? Also, do I edit the HTML files directly - whilst adding the UTF-8 header to assure the characters will show correctly - or do I send you the translation on any other form?
Have a nice day! :D

User avatar
mnh48
Member
Posts: 310
Joined: Wed Nov 16, 2016 22:55
GitHub: mnh48
IRC: MNH48
In-game: mnh48
Location: Kuala Lumpur, Malaysia
Contact:

Re: Modding Tutorial Book (new: BasicMapOps, AutoErrorChecki

by mnh48 » Post

MineYoshi wrote:Hi, Rubenwardy. Recently I got illuminated while eating a piece of chicken and I got the idea of translating your modding tutorial to Spanish. Do you allow me to do so? Also, do I edit the HTML files directly - whilst adding the UTF-8 header to assure the characters will show correctly - or do I send you the translation on any other form?
there's instruction on how to add language on the website
https://rubenwardy.com/minetest_modding ... w-language

just follow that for any languages... but it will take some time to translate as there's many pages
(am translating the book to Malay locally at the moment, will only make pull request once everything is translated)

User avatar
MineYoshi
Member
Posts: 5373
Joined: Wed Jul 08, 2015 13:20
Contact:

Re: Modding Tutorial Book (new: BasicMapOps, AutoErrorChecki

by MineYoshi » Post

muhdnurhidayat wrote:
MineYoshi wrote:Hi, Rubenwardy. Recently I got illuminated while eating a piece of chicken and I got the idea of translating your modding tutorial to Spanish. Do you allow me to do so? Also, do I edit the HTML files directly - whilst adding the UTF-8 header to assure the characters will show correctly - or do I send you the translation on any other form?
there's instruction on how to add language on the website
https://rubenwardy.com/minetest_modding ... w-language

just follow that for any languages... but it will take some time to translate as there's many pages
(am translating the book to Malay locally at the moment, will only make pull request once everything is translated)
Oh. Thank you very much. :-)
Have a nice day! :D

User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Crazy idea for which I will get shouted at by every core dev

by Wuzzy » Post

Crazy idea for which I will get shouted at by every core dev: Include the modding book into the Minetest repository.

User avatar
TumeniNodes
Member
Posts: 2941
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: Crazy idea for which I will get shouted at by every core

by TumeniNodes » Post

Wuzzy wrote:Crazy idea for which I will get shouted at by every core dev: Include the modding book into the Minetest repository.
Why?
Not being argumentative or a smartass..., legitimately asking why. What would be the reason, and the benefit, etc..

IMO it is better as a separate project. If it were merged in or lumped in, it may create some confusion and neglect over time
A Wonderful World

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: Modding Tutorial Book (new: BasicMapOps, AutoErrorChecki

by texmex » Post

Alternative idea: Rewrite the dull default repo readme to include an ”awesome-minetest” style section of important community repos and web sites.

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 test

by rubenwardy » Post

New Chapters!

Also added previous next chapter links, and changed a lot of the URLs.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
TumeniNodes
Member
Posts: 2941
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: Modding Tutorial Book (new: Code architecture, unit test

by TumeniNodes » Post

rubenwardy wrote:

New Chapters!

Also added previous next chapter links, and changed a lot of the URLs.
Next: Point all wiki dev link to the modding book ; )
A Wonderful World

cryptavian
New member
Posts: 1
Joined: Thu Sep 06, 2018 04:42

Re: Modding Tutorial Book (new: Code architecture, unit test

by cryptavian » Post

Is the IDE/Lua debugging section still accurate and up-to-date? At the very least I think server property "secure.enable_security false" needs to be set in order for the "require('debugger')" line to grab the correct module without triggering mod security exceptions.

After setting that and the subsequent steps, I still got the error that follows Lua Runtime error "module 'socket.core' not found" from within debugger.lua; does anyone know what I'm doing wrong?

Code: Select all

2018-09-06 04:36:55: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'mobs_monster' in callback LuaABM::trigger(): /usr/local/lib/lua/5.1/debugger.lua:53: module 'socket.core' not found:
2018-09-06 04:36:55: ERROR[Main]:       no field package.preload['socket.core']
2018-09-06 04:36:55: ERROR[Main]:       no file './socket/core.lua'
2018-09-06 04:36:55: ERROR[Main]:       no file '/usr/local/share/lua/5.1/socket/core.lua'
2018-09-06 04:36:55: ERROR[Main]:       no file '/usr/local/share/lua/5.1/socket/core/init.lua'
2018-09-06 04:36:55: ERROR[Main]:       no file '/usr/local/lib/lua/5.1/socket/core.lua'
2018-09-06 04:36:55: ERROR[Main]:       no file '/usr/local/lib/lua/5.1/socket/core/init.lua'
2018-09-06 04:36:55: ERROR[Main]:       no file './socket/core.so'
2018-09-06 04:36:55: ERROR[Main]:       no file '/usr/local/lib/lua/5.1/socket/core.so'
2018-09-06 04:36:55: ERROR[Main]:       no file '/usr/local/lib/lua/5.1/loadall.so'
2018-09-06 04:36:55: ERROR[Main]:       no file './socket.so'
2018-09-06 04:36:55: ERROR[Main]:       no file '/usr/local/lib/lua/5.1/socket.so'
2018-09-06 04:36:55: ERROR[Main]:       no file '/usr/local/lib/lua/5.1/loadall.so'
2018-09-06 04:36:55: ERROR[Main]: stack traceback:
2018-09-06 04:36:55: ERROR[Main]:       [C]: in function 'require'
2018-09-06 04:36:55: ERROR[Main]:       /usr/local/lib/lua/5.1/debugger.lua:53: in main chunk
2018-09-06 04:36:55: ERROR[Main]:       [C]: in function 'require'
2018-09-06 04:36:55: ERROR[Main]:       /path/to/minetest/bin/../mods/mobs/api.lua:3212: in function </path/to/minetest/bin/../mods/mobs/api.lua:3211>
Here are the steps I followed from: https://rubenwardy.com/minetest_modding ... vironments
IDEs allow you to debug code like a native application. These are harder to set up than just a text editor.

One such IDE is Eclipse with the Koneki Lua plugin:
  • Install Eclipse + Koneki.
    Create a new Lua project from existing source (specify Minetest’s base directory).
    Follow instructions from Koneki wiki how to do “Attach to remote Application” debugging (just a few steps).
    It is suggested to add those lines from wiki at beginning of builtin.lua.
    Start the debugger (set “Break on first line” in debugger configuration to see if it is working).
    Start Minetest.
    Enter the game to startup Lua.
EDIT - Update

I resolved this issue by running "luarocks install luasocket" which downloaded and installed the appropriate socket library onto my system's Lua path thanks to help on Discord from rubenwardy and others. Debugging through Eclipse Koneki works great now!

User avatar
Kilarin
Member
Posts: 894
Joined: Mon Mar 10, 2014 00:36
GitHub: Kilarin

Re: Modding Tutorial Book (new: Code architecture, unit test

by Kilarin » Post

Just wanted to add my voice to the other saying that this book is AWESOME and very helpful. THANK YOU!

User avatar
FrostRanger
Member
Posts: 80
Joined: Thu Oct 11, 2018 05:40
GitHub: WulftheNordicRanger
IRC: FrostRanger FrostRanger[m]
In-game: FrostRanger FrostStar
Location: In the untamed wilderness of wherever I happen to be dimension hopping this time...
Contact:

Re: Modding Tutorial Book (new: Code architecture, unit test

by FrostRanger » Post

Koneki does not seem to be in the eclipse marketplace (well, it is, but it is not for lua though). The only thing that seems to be available for lua in the eclipse marketplace is Lua Development Tools. Just staring out with modding so I haven't had a chance to play around with it much but it seems to work fine. Thank you for making this awesome resource!
Sole ranger and ruler of the frozen realms of Cabin Fever and seeker of the ever elusive Dungeon Master...

User avatar
markthesmeagol
Member
Posts: 34
Joined: Fri Dec 21, 2018 13:15
GitHub: smeagolthellama
In-game: haivets

Re: Modding Tutorial Book (new: Code architecture, unit test

by markthesmeagol » Post

I have a bit of a complaint. The games chapter seems rather lacking. Are there any other resources on making games?
I am not very good at lua. I am learning though.

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 test

by rubenwardy » Post

markthesmeagol wrote:I have a bit of a complaint. The games chapter seems rather lacking. Are there any other resources on making games?
Making games in Minetest is basically just writing a load of mods. What exactly would you find useful to read about?

There's also this topic, which was created today: viewtopic.php?f=49&t=22932
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
markthesmeagol
Member
Posts: 34
Joined: Fri Dec 21, 2018 13:15
GitHub: smeagolthellama
In-game: haivets

Re: Modding Tutorial Book (new: Code architecture, unit test

by markthesmeagol » Post

Well, to start off, a summary of what each file is, especially minetest.conf and settingstypes.txt. Also, something about where one should go to get a default mod. Minetest-game's default is a bit bloated, and writing my own from scratch isn't very appealing.

Also, since most games contain a number of third-party mods, it might be a good idea to give instructions on how to check licenses and stuff for compatibility issues, or worse.

Another thing that might be nice would be a list of commonly used, high-quality mods, that would be recommended for consideration in the interests of inclusion.
I am not very good at lua. I am learning though.

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

First up really find the book helpful, I reference it and the API as frequently as each other

I'm just starting to look a bit more sfinv and overriding a page and tried the example at the very bottom of this chapter:
https://rubenwardy.com/minetest_modding ... sfinv.html

Hit an error and after playing around a bit (I'm using MT5.3) and the below I seemed to have to update the first line to change "registered_pages" to "pages". I then get my nice little "Hello" printing in the top left corner.

Code: Select all

local old_func = sfinv.pages["sfinv:crafting"].get   -- Update this line?
sfinv.override_page("sfinv:crafting", {
    get = function(self, player, context, ...)
        local ret = old_func(self, player, context, ...)

        if type(ret) == "table" then
            ret.formspec = ret.formspec .. "label[0,0;Hello]"
        else
            -- Backwards compatibility
            ret = ret .. "label[0,0;Hello]"
        end

        return ret
    end
})

doxygen_spammer
Member
Posts: 70
Joined: Wed Dec 16, 2020 16:52
GitHub: doxygen-spammer

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

by doxygen_spammer » Post

(I’m confused, because I posted this question yesterday already. Probably I clicked “Preview”, and then went over to something else, and at some time closed that tab. I do that frequently, in my email client, in patch reviews, in other forums, in the SMS app, ...)

So my question was about the section “Basic Map Operation”:
Note how we compared the squared distance from the position, rather than square rooting it to obtain the actual distance. This is because computers find square roots computationally expensive, so you should avoid them as much as possible.
I wonder whether the square root is actually expensive compared to executing this comparatively complex Lua code: delta.x*delta.x + delta.y*delta.y <= 5*5. Additionally, there is vector.distance() from the Minetest API, which looks more suited for that task, and calculating the distance in C is probably still faster than calculating squares in Lua. Right?

I also think you forgot to respect the Z axis?

---

Ok, vector.distance() is actually implemented internally in Lua, and even calculates squares and sums twice! Maybe implement buildin/ stuff in C rather than Lua?

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

doxygen_spammer wrote:
Thu Dec 24, 2020 19:37
I wonder whether the square root is actually expensive compared to executing this comparatively complex Lua code: delta.x*delta.x + delta.y*delta.y <= 5*5.
It's cheaper to multiply two numbers than to do a square root. Note that the code to do it with square root would be as follows:

math.sqrt(delta.x*delta.x + delta.y*delta.y) <= 5.
doxygen_spammer wrote:
Thu Dec 24, 2020 19:37
I also think you forgot to respect the Z axis?
This is a good point, it should have the z-axis as well. I've updated the book to correct this
doxygen_spammer wrote:
Thu Dec 24, 2020 19:37
Ok, vector.distance() is actually implemented internally in Lua, and even calculates squares and sums twice! Maybe implement buildin/ stuff in C rather than Lua?
Lua is fast, especially with LuaJIT, but changing between Lua and C is not
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

The HUD work not:

Code: Select all

minetest.on_joinplayer({
  local player = minetest.get_player_by_name("username")
  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
    })
})

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests