Debug Log Output when modding

Post Reply
orangutan
New member
Posts: 1
Joined: Sun Nov 16, 2025 22:01

Debug Log Output when modding

by orangutan » Post

Hey, I am trying to learn mod development. I am new to Luanti and Lua. Thus, I am having tons of errors in my code. I can never make it work as I intended.

When I develop games in Unity, I always use "Debug.Log()" to print out a message right after a function or a condition, to check if that line of code is working. Or, I print out values of variables to check how they are responding to my script. These logs would always be easily readible at the below of the screen in console window.

I saw that there were core.log and core.chat_send_all, core.log, core.debug. But I couldnt properly run them also. I only managed to run chat_send_all just once and never more. I tried it on new worlds also but still couldnt run it again. I cant run my code probably and cant even run my debug functions to find the problem and fix it.

So what can I do? Thanks.

Code: Select all

core.chat_send_all("AAAAAA MOD STARTED")
local modname = "arachnophobia_mode"
core.chat_send_all(modname)

local path = core.get_modpath(modname)
core.chat_send_all(path)

local greedy_cows_def = {
    --	visual_size = {x=3, y=3, z=3}
    follow = "mcl_core:diamond",
    drops = {
        {name = "mcl_core:dirt",
            chance = 1,
            min = 1,
            max = 3,
            looting = "common",}
    },
}

core.chat_send_all("greedy def")

override:rewrite("mobs_mc:cow", greedy_cows_def)

--dofile(path .. "/entity_override_tables/attempt_on_cow.lua")
core.chat_send_all("init.lua dofile")
I am trying to develop a mod using https://github.com/taikedz-mt/entity_override.

maybe off topic but i feel like even if I change the code, save it and reopen the world. My code doesnt get updated. maybe i should start another topic for this.

rstcxk
Member
Posts: 105
Joined: Mon Jul 08, 2024 22:06

Re: Debug Log Output when modding

by rstcxk » Post

There are 2 places you can see these logs:

${MINETEST_HOME}/debug.txt. Where ${MINETEST_HOME} is usually ~/.minetest, but you can click the "open user data directory" in the about section and open it in file explorer

Another way is to open luanti in a terminal, now all logs will be shown there (my preferred setup)

I recommend using core.debug while debugging, it makes it easier to find which prints are for debugging, and which should stay when you finalize the mod

Also, while printing stuff like tables i recommend using the dump function, so

Code: Select all

local my_tab = {xyz = "lol", abc = 12}
core.debug(dump(my_tab))
orangutan wrote:
Mon Nov 17, 2025 16:29
maybe off topic but i feel like even if I change the code, save it and reopen the world. My code doesnt get updated. maybe i should start another topic for this.
are you editing the file in the mod directory? If so, it should work

You should probably read the message that comes up when you crash, it points towards what exactly failed

User avatar
Linuxdirk
Member
Posts: 3357
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Debug Log Output when modding

by Linuxdirk » Post

orangutan wrote:
Mon Nov 17, 2025 16:29
Or, I print out values of variables to check how they are responding to my script. These logs would always be easily readible at the below of the screen in console window.
This prints the content of a variable in a usable way. It also formats the table so it is easily readable:

Code: Select all

print(dump(my_cool_variable))
dump() gives you the printable string and print() is just the Lua function for printing out a given string. print()'s output is shown in the console you started Luanti from.

User avatar
Blockhead
Moderator
Posts: 2783
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: Debug Log Output when modding

by Blockhead » Post

As a new developer who might not have been exposed to a lot of tools, I recommend Debug mod so you can run Lua interactively (WorldEdit also has //lua, but that is not as nice in its formatting; a lot of server owners do use it though..). Also QA-Block to explore the global variable space, especially core.registered_* tables.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests