Jump to content

Recommended Posts

This mod 394470072 or "Additional set pieces" used to work just fine until recently it is crashing my game. I got help from someone to help narrow it down but i now need to fix it because it is preventing me from joining my 100 day + world. Here is the file it corrupts and the server log for master caves seems to be ok

colourful_mushroom_farm.lua server_log_2022-01-18-14-18-49.txt

Edited by Riot_
I would appreciate if anyone would help me debug it

Try replacing the OnLoad function with this one:

Spoiler

-- This function is called when the scenario is created.
local function OnLoad(inst, scenariorunner)
	SetTrapOnEntities(inst, scenariorunner)

	for i = 1, 5 do
		local poop = GetPoop(inst)
        
        if poop and next(poop) ~= nil then
		    local v = poop[math.random(#poop)]
	 	    local x, y, z = v.Transform:GetWorldPosition()
		 	    v.scene_putininventoryfn = function(inst) 
		 		    			OnTriggerTrap(inst, scenariorunner, x, y, z) 
		 			    	end
		 	    v:ListenForEvent("onpickup", v.scene_putininventoryfn)
        end
	end
end

 

This kind of error can happen if your list is empty, as the lenght is 0 in this case and math.random(x) == math.random(1,x), which would be in this case math.random(1,0) which causes an error.

By checking next(poop), you check if the table has a least 1 entry.

  • Thanks 1
10 hours ago, Monti18 said:

Try replacing the OnLoad function with this one:

  Hide contents


-- This function is called when the scenario is created.
local function OnLoad(inst, scenariorunner)
	SetTrapOnEntities(inst, scenariorunner)

	for i = 1, 5 do
		local poop = GetPoop(inst)
        
        if poop and next(poop) ~= nil then
		    local v = poop[math.random(#poop)]
	 	    local x, y, z = v.Transform:GetWorldPosition()
		 	    v.scene_putininventoryfn = function(inst) 
		 		    			OnTriggerTrap(inst, scenariorunner, x, y, z) 
		 			    	end
		 	    v:ListenForEvent("onpickup", v.scene_putininventoryfn)
        end
	end
end

 

This kind of error can happen if your list is empty, as the lenght is 0 in this case and math.random(x) == math.random(1,x), which would be in this case math.random(1,0) which causes an error.

By checking next(poop), you check if the table has a least 1 entry.

OMG THAT FIX IT THE WORLD WORKS AGAIN THANK YOU SO MUCH YOU SAVED ME SO MUCH TIME AND EFFORT

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