Eusong Posted May 7, 2018 Share Posted May 7, 2018 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 More sharing options...
ksaab Posted May 9, 2018 Share Posted May 9, 2018 (edited) 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 May 9, 2018 by ksaab Link to comment Share on other sites More sharing options...
Eusong Posted May 10, 2018 Author Share Posted May 10, 2018 Gah! Thank you so much! I never would've figured that out on my own. Link to comment 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