Jump to content

Unable to get a task to work


Recommended Posts

Spoiler

inst:ListenForEvent("moisturedelta", function()
		if inst.components.moisture and inst.components.moisture:GetMoisturePercent() == 1 then
			if not inst:HasTag("playerghost") then
				for k, v in pairs(inst.components.disease.diseases) do
					if v == "hypothermia" or v == "rust" then
					
					else
						if inst.prefab == wx78 then
							inst.components.disease.adddisease(inst, "rust")
						else
							inst.components.disease:adddisease(inst, "hypothermia")
						end
					end
				end
			end
		end
	end)

 

I know it's not the inst.components.disease.adddisease that isn't working, it's a problem with that function I posted. I'm so confused as to why it won't work. I put that chunk of code under the local Disease = Class(function(self, inst)

Link to comment
Share on other sites

if you tested it as wx78:
 

if inst.prefab == wx78 then

will be always false because you compare prefab with an undefined variable. The correct variant:
 

if inst.prefab == "wx78" then

You also call the adddisease functions in two different ways (with ':' and with '.').

If you have more than two diseases, then your cycle is absolutely wrong — when it finds a disease different from hypothermia or rust, it calls adddisease(). Try something like this instead of your cycle:

if inst.prefab == "wx78" and not table.contains(inst.components.disease.diseases, "rust") then
	inst.components.disease:adddisease(inst, "rust")
elseif not table.contains(inst.components.disease.diseases, "hypothermia") then
	inst.components.disease:adddisease(inst, "hypothermia")
end

 

Edited by ksaab
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...