Farxodor Posted November 23, 2016 Share Posted November 23, 2016 Hi, I'm having issues using a global function (it returns nil when I believe it shouldn't be). In builder.lua, there is code that determines if the crafting player already has a pet: function Builder:DoBuild(recname, pt, rotation, skin) local recipe = GetValidRecipe(recname) if recipe ~= nil and (self:IsBuildBuffered(recname) or self:CanBuild(recname)) then if recipe.placer ~= nil and self.inst.components.rider ~= nil and self.inst.components.rider:IsRiding() then return false, "MOUNTED" elseif recipe.level.ORPHANAGE > 0 and ( self.inst.components.petleash == nil or self.inst.components.petleash:IsFull() or self.inst.components.petleash:HasPetWithTag("critter") ) then return false, "HASPET" end ... I'm attempting to do something similar to this, but I wanted to avoid modifying builder.lua directly. So I'm using AddComponentPostInit to modify Builder:DoBuild. AddComponentPostInit("builder", function(self) local _DoBuild = self.DoBuild self.DoBuild = function(recname, ...) local recipe = GLOBAL.GetValidRecipe(recname) --This always seems to return nil, even though it works within builder.lua ... return _DoBuild(recname, ...) end end) What am I doing incorrectly with GetValidRecipe? Thanks. Link to comment https://forums.kleientertainment.com/forums/topic/71945-usage-of-global-functions/ Share on other sites More sharing options...
CarlZalph Posted November 23, 2016 Share Posted November 23, 2016 49 minutes ago, Farxodor said: Hi, I'm having issues using a global function (it returns nil when I believe it shouldn't be). In builder.lua, there is code that determines if the crafting player already has a pet: I'm attempting to do something similar to this, but I wanted to avoid modifying builder.lua directly. So I'm using AddComponentPostInit to modify Builder:DoBuild. What am I doing incorrectly with GetValidRecipe? Thanks. AddComponentPostInit("builder", function(self) local _DoBuild = self.DoBuild self.DoBuild = function(self, recname, ...) local recipe = GLOBAL.GetValidRecipe(recname) --This always seems to return nil, even though it works within builder.lua ... return _DoBuild(self, recname, ...) end end) In LUA the object:funcname(arg1) is shorthand for object.funcname(object, arg1) Link to comment https://forums.kleientertainment.com/forums/topic/71945-usage-of-global-functions/#findComment-840795 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now