In a previous version of Minetest, Minetest showed a warning directly on the interface when an undeclared global variable has been accessed.
But now, this feature got removed again and it is only written in debug.txt.
Personally, I find this warning one of the most useful warnings of Minetest, because accessing undeclared global variables is not only bad practice, but a likely cause of bugs. Just today I have squashed another bug with the help of these warnings.
IMO a good Lua script should avoid this completely.
First question: How do I get the undeclared global variable warning on interface?
Second question: Why is it not shown in the interface by default anymore? I know, many mods use this kind of bad practise, so you'll get many such warnings, but it is unintentionally most of the time and it is very easy to forget a “local” and (seemingly) get away with it.
Screaming it right into the interface would force mod makers to fix this kind of bad practice. Also, because mod users would quickly start to complain. But maybe there is a better rationale to remove it from the interface anyways?
But I certainly want Minetest to scream loudly and proudly this warning to the interface, at least in my Minetest installation.
Here are some examples of the warning messages I am talking about:
16:29:15: WARNING: Undeclared global variable "pos" accessed at ...test/games/hungry_games/mods/hungry_games/engine.lua:27
16:30:57: WARNING: Assignment to undeclared global "obj" inside a function at ...test/games/hungry_games/mods/hungry_games/engine.lua:36.
16:30:57: WARNING: Assignment to undeclared global "winnerPos" inside a function at ...test/games/hungry_games/mods/hungry_games/engine.lua:107.
16:30:57: WARNING: Assignment to undeclared global "winnerName" inside a function at ...test/games/hungry_games/mods/hungry_games/engine.lua:108.
Most of these bugs are fixed by simply writing “local” in front of the name. Or you make an explicit global assignment to the variable beforehand, if it was that you wanted to do.