Jump to content

What is the purpose of restarting update task in perishable component?


Rickzzs
  • Pending
function Perishable:StartPerishing()
    if self.updatetask ~= nil then
        self.updatetask:Cancel()
        self.updatetask = nil
    end

    local dt = 10 + math.random()*FRAMES*8
	self.start_dt = math.random()*2
    self.updatetask = self.inst:DoPeriodicTask(dt, Update, self.start_dt, dt)
end

I don't understand why it is necessary to restart the update task.

In an experiment with acid rain, I find that the task is always restarting because of ReducePercent->SetPercent->StartPerishing caller. But I don't see any cached perish time in the update function.

The logic has a flaw in that if the task is restarted each time, there is a delay in running it, so that a task can be skipped until it is started next time by chance. So whenever a task is skipped, the perish time remains the same. However, acid rain does not necessarily reduce enough amount of perish time to compensate for it. This will result in an actual <1 rate of perish.

The described circumstance may not be likely to happen in the game, but it can be reproduced by keeping the moisture at a fairly low level, so that acid rain is weak enough not to perish food.


Steps to Reproduce

read the code.

  • Like 1



User Feedback


There are no comments to display.



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