WubbleWubble Posted October 6, 2022 Share Posted October 6, 2022 I'm trying to modify the Weather component in order to trigger the client snow fx while within range of a certain structure. I did this, of course, through AddComponentPostInit using this code AddComponentPostInit("weather", function(self) -- Overriding OnUpdate local old_OnPostInit = self.OnPostInit function self:OnPostInit() if GLOBAL.ThePlayer ~= nil then local x, y, z = GLOBAL.ThePlayer.Transform:GetWorldPosition() local wubtree = TheSim:FindEntities(x, y, z, 32, {"wubbelplant"}) if #wubtree > 0 then _snowfx:PostInit() else old_OnPostInit() end end end end) However this gives me the following error [00:01:27]: [string "../mods/workshop-2864019566/modmain.lua"]:211: attempt to index global '_snowfx' (a nil value) LUA ERROR stack traceback: ../mods/workshop-2864019566/modmain.lua:211 in (method) OnPostInit (Lua) <206-216> self = GetDebugString = function - scripts/components/weather.lua:1016 OnSave = function - scripts/components/weather.lua:949 inst = 100041 - forest_network (valid:true) OnLoad = function - scripts/components/weather.lua:981 OnRemoveEntity = function - scripts/components/weather.lua:751 LongUpdate = function - scripts/components/weather.lua:773 OnUpdate = function - scripts/components/weather.lua:773 OnPostInit = function - ../mods/workshop-2864019566/modmain.lua:206 x = 181.03500366211 y = -0.0020000000949949 z = 276.8030090332 wubtree = table: 000000008266C290 scripts/components/weather.lua:458 in (local) fn (Lua) <452-460> src = 100037 - world (valid:true) player = 115893 - snowman (valid:true) However, _snowfx is defined in the component that this should be adding to, so why is it not allowing the additions to the component to use these values? The very function that's being modified uses the same syntax to call the snow effect. Here is the part of the weather component we are using -------------------------------------------------------------------------- --[[ Post initialization ]] -------------------------------------------------------------------------- if _hasfx then function self:OnPostInit() if _preciptype:value() == PRECIP_TYPES.rain then _rainfx:PostInit() elseif _preciptype:value() == PRECIP_TYPES.snow then _snowfx:PostInit() end if _season == "summer" then _pollenfx:PostInit() end end end Anyone have any ideas whats going wrong here, or how I could fix this? Link to comment https://forums.kleientertainment.com/forums/topic/143600-having-issues-with-addcomponentpostinit/ Share on other sites More sharing options...
Rickzzs Posted October 6, 2022 Share Posted October 6, 2022 You need to learn Lua's grammar. _snowfx is a local value, in this function an upvalue. You can't access it in your post init hook function because the environments are different. You may want debug.getupvalue Link to comment https://forums.kleientertainment.com/forums/topic/143600-having-issues-with-addcomponentpostinit/#findComment-1601290 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