mirror of
https://gitlab.com/rubenwardy/awards.git
synced 2025-07-12 21:00:24 +02:00
Fix use of uninitialized data.
Since groups were notified before the `__total` count was initialized (and groups can't initialize `__total`), when run_callbacks tried to access `__total` it got `nil`. This is fixed by moving the notification of groups to *after* the counter is incremented and `__total` is initialized.
This commit is contained in:
@ -141,17 +141,6 @@ function awards.register_trigger(tname, tdef)
|
|||||||
function tdef.notify(player, key, n)
|
function tdef.notify(player, key, n)
|
||||||
n = n or 1
|
n = n or 1
|
||||||
|
|
||||||
if tdef.key_is_item and key:sub(1, 6) ~= "group:" then
|
|
||||||
local itemdef = minetest.registered_items[key]
|
|
||||||
if itemdef then
|
|
||||||
for groupname,rating in pairs(itemdef.groups or {}) do
|
|
||||||
if rating ~= 0 and tdef.watched_groups[groupname] then
|
|
||||||
tdef.notify(player, "group:" .. groupname, n)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
assert(player and player.is_player and player:is_player() and key)
|
assert(player and player.is_player and player:is_player() and key)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local data = awards.player(name)
|
local data = awards.player(name)
|
||||||
@ -164,6 +153,17 @@ function awards.register_trigger(tname, tdef)
|
|||||||
data[tname].__total = (data[tname].__total or 0) + n
|
data[tname].__total = (data[tname].__total or 0) + n
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if tdef.key_is_item and key:sub(1, 6) ~= "group:" then
|
||||||
|
local itemdef = minetest.registered_items[key]
|
||||||
|
if itemdef then
|
||||||
|
for groupname,rating in pairs(itemdef.groups or {}) do
|
||||||
|
if rating ~= 0 and tdef.watched_groups[groupname] then
|
||||||
|
tdef.notify(player, "group:" .. groupname, n)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
tdef:run_callbacks(player, data, function(entry)
|
tdef:run_callbacks(player, data, function(entry)
|
||||||
local current
|
local current
|
||||||
if entry.key == key then
|
if entry.key == key then
|
||||||
|
Reference in New Issue
Block a user