Jump to content

Having issues with AddComponentPostInit


Recommended Posts

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
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
 Share

×
  • Create New...