Jump to content

Mysterious nil values

Recommended Posts

How come print(item) from ModOnEquip outputs the item correctly upon item equip but print(item.prevslot) always outputs nil?

And why does print(item) from ModUnequip output nil when the item is right-clicked from the equip slot but outputs the item correctly when it is left-clicked instead?

local ENV = env
GLOBAL.setfenv(1, GLOBAL)

local function ModOnEquip(_, data)
    if type(data) == "table" and data.eslot and data.item then
        local item = data.item

local function ModOnUnequip(inst, data)
    if type(data) ~= "table" then return end
    local item = data.item

ENV.AddComponentPostInit("playercontroller", function(self)
    if self.inst ~= ThePlayer then return end
    self.inst:ListenForEvent("equip", ModOnEquip)
    self.inst:ListenForEvent("unequip", ModOnUnequip)

    local OnRemoveFromEntity = self.OnRemoveFromEntity
    self.OnRemoveFromEntity = function(self, ...)
        self.inst:RemoveEventCallback("equip", ModOnEquip)
        self.inst:RemoveEventCallback("unequip", ModOnUnequip)
        return OnRemoveFromEntity(self, ...)

I'm fairly new to modding (have made only one server mod so far, so I'm still analyzing stuff when it comes to client side mods). Can anyone please enlighten me about the above or give me related beginner-friendly guides?

Edited by GrowthMindset
some corrections
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...