EmptyStar / researcher

Adds an "earned creative" mode to Minetest
Other
0 stars 0 forks source link

crashes without awards mod enabled #1

Closed programmerjake closed 2 days ago

programmerjake commented 1 month ago

Reproduction steps: create new minetest game world with researcher but without awards try to research a stack of items observe it crashing:

AsyncErr: Lua: Runtime error from mod '' in callback on_playerReceiveFields(): ....minetest.Minetest/.minetest/mods/researcher/src/gui.lua:368: attempt to index global 'awards' (a nil value)
stack traceback:
    ....minetest.Minetest/.minetest/mods/researcher/src/gui.lua:368: in function 'do_research'
    ....minetest.Minetest/.minetest/mods/researcher/src/gui.lua:445: in function <....minetest.Minetest/.minetest/mods/researcher/src/gui.lua:443>
    /app/share/minetest/builtin/common/register.lua:26: in function </app/share/minetest/builtin/common/register.lua:12>
NathanSalapat commented 1 month ago

Having the same issue, fixed the error by simply adding if awards then awards.unlock(player_name, "researcher:eureka") end in gui.lua Tested with and without the awards mod, and the award is given when the award mod is enabled, and no crash when it's not.

EmptyStar commented 2 days ago

Thanks for reporting this issue. I usually try to catch cases like this but I must have missed this condition. The Awards mod is meant to be optional and the fix you've described is exactly what Researcher needs. I'll get this change merged very soon.

programmerjake commented 2 days ago

if awards then awards.unlock(player_name, "researcher:eureka") end

note you'll want to use core.global_exists("awards") instead of just awards to avoid triggering a warning on accessing a non-existent global

EmptyStar commented 2 days ago

Actually, checking if researcher.settings.awards then ... is the most thorough check as it ensures that awards are enabled in the settings and also checks that the modpath is defined which indicates that the Awards mod is loaded. I already have this check in api.lua for other award unlocks, I just missed it here. I'm cooking up a quick little PR to add the check.

EmptyStar commented 2 days ago

Done! Thanks again for reporting this issue! I'll also get this released to ContentDB.