Keyanes Posted July 26, 2018 Share Posted July 26, 2018 After countless hours of tweaking and testing it in game, I dont know whats wrong with the code local function CheckTemperature(inst) local temp = inst.components.temperature:GetCurrent() if temp > 40 and temp <= 69 then inst.components.health:StartRegen(1.5, 2) end if temp > 30 and temp <= 39 then inst.components.health:StartRegen(0.5, 3) end if temp > 29 then inst.components.health:StartRegen(0, 0) end inst:DoPeriodicTask( 0.0, function(inst) CheckTemperature(inst) end) end Can someone help me ;-; My goal was to let the char regen health based on temp Link to comment Share on other sites More sharing options...
Kronas Posted July 26, 2018 Share Posted July 26, 2018 not an expert but try changing inst.components.health:StartRegen(1.5, 2) to inst.components.health:DoDelta(1.5, 2) Link to comment Share on other sites More sharing options...
Keyanes Posted July 26, 2018 Author Share Posted July 26, 2018 2 hours ago, Kronas said: not an expert but try changing inst.components.health:StartRegen(1.5, 2) to inst.components.health:DoDelta(1.5, 2) Thanks for the reply, sadly it still doesn't regen Link to comment Share on other sites More sharing options...
Wolf_EX Posted July 26, 2018 Share Posted July 26, 2018 inst:DoPeriodicTask( 0.0, function(inst) CheckTemperature(inst) end) I'm not sure if how you are doing it works or not but usually you set it to a variable like inst.tasktemp = inst.DoPeriodicTask(.5, CheckTemperature, nil) And also you are calling it in the function that you are repeating which isn't necessary, you just need it in the main function. I haven't tested it but I think using inst:ListenForEvent("temperaturedelta", CheckTemperature) would be better than DoPeriodicTask. Link to comment Share on other sites More sharing options...
ksaab Posted July 26, 2018 Share Posted July 26, 2018 (edited) You have wrong condtions. Let the temperature be 65: if temp > 40 and temp <= 69 then --true inst.components.health:StartRegen(1.5, 2) end if temp > 30 and temp <= 39 then --false inst.components.health:StartRegen(0.5, 3) end if temp > 29 then --true inst.components.health:StartRegen(0, 0) end 2 of 3 conditions are valid and the last regen overwrites the first. But I think you just place wrong symbol for the last one (temp < 29). And as @Wolf_EX said — it will be better to replace inst:DoPeriodicTask by inst:ListenForEvent("temperaturedelta", CheckTemperature) and move it to the main prefab function. Edited July 26, 2018 by ksaab Link to comment Share on other sites More sharing options...
Keyanes Posted July 27, 2018 Author Share Posted July 27, 2018 (edited) 18 hours ago, Wolf_EX said: inst:DoPeriodicTask( 0.0, function(inst) CheckTemperature(inst) end) I'm not sure if how you are doing it works or not but usually you set it to a variable like inst.tasktemp = inst.DoPeriodicTask(.5, CheckTemperature, nil) And also you are calling it in the function that you are repeating which isn't necessary, you just need it in the main function. I haven't tested it but I think using inst:ListenForEvent("temperaturedelta", CheckTemperature) would be better than DoPeriodicTask. It worked but for some reason the conditions got reversed , (HP regens when temp is below 40) had to reverse it on code and it works great! Thank you so much T__T 17 hours ago, ksaab said: You have wrong condtions. Let the temperature be 65: if temp > 40 and temp <= 69 then --true inst.components.health:StartRegen(1.5, 2) end if temp > 30 and temp <= 39 then --false inst.components.health:StartRegen(0.5, 3) end if temp > 29 then --true inst.components.health:StartRegen(0, 0) end 2 of 3 conditions are valid and the last regen overwrites the first. But I think you just place wrong symbol for the last one (temp < 29). And as @Wolf_EX said — it will be better to replace inst:DoPeriodicTask by inst:ListenForEvent("temperaturedelta", CheckTemperature) and move it to the main prefab function. Ah! thank you so that's why it never regenerated health ;-; Edited July 27, 2018 by Keyanes 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