jbruechert / agriculture

6 stars 3 forks source link

Undeclared global variable "composter_on_metadata_inventory_move" generates WARNING #17

Open npalix opened 4 years ago

npalix commented 4 years ago

https://github.com/JBBgameich/agriculture/blob/96d48538ea95dce131556f792368b543f4f6dc4c/compost/init.lua#L300

WARNING[Main]: Undeclared global variable "composter_on_metadata_inventory_move" accessed at [...]/mods/agriculture/compost/init.lua:300

jbruechert commented 4 years ago

@lnjX Could you look into this please?

npalix commented 4 years ago

There is also the same thing with the following line. Undeclared global variable "gardens" accessed at [...]/mods/agriculture/gardens/init.lua:11

jakimfett commented 4 years ago

Am seeing this as well.

It looks like there's a missing function, composter_on_metadata_inventory_move, and there's two similarly titled functions already in the file. Both functions log the action, and they both trigger the same composter_update_state function, see lines #252 & #262 respectively.

I was able to find the use of the same assignment (on_metadata_inventory_move = something) in the protectors mod, so with those datapoints I've attempted a cobbled together a fix for this that...seems to work, though I'm still testing it on my dev server.

WARNING: am reasonably certain there's more this function was intended to do...the compost bin probably isn't going to work correctly.

local function composter_on_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
    core.log("action", player:get_player_name() .. " takes moves stuff incompost bin at " .. core.pos_to_string(pos))
    local meta = core.get_meta(pos)
    composter_update_state(pos, meta, meta:get_inventory())
end

Sharing my progress so others can test it too, and I'll add a proper pull request once I finish tinkering.

Analysis of the rest of the mod would be necessary to determine if moving things inside the compost bin inventory should do anything, and really the only person who can answer this is the original author of this file, if the answer exists at all.

jakimfett commented 4 years ago

@npalix the gardens one is working as intended, per my best guess about the code.

See this commit for the bits I've added to contextualize it.