Job overflow

Discussion about Mods for Prison Architect

Moderator: NBJeff

neoxes
level1
level1
Posts: 29
Joined: Mon Aug 26, 2013 10:49 am

Job overflow

Postby neoxes » Wed Oct 19, 2016 11:00 am

I reported this to Mantis:

If you call a custom job at every update cycle with CreateJob function, the game will prevent "overflow" creating just one istance of that job.
It is good, but if you call a SECOND custom job at every update cycle, the game WILL NOT prevent "overflow", creating lots of istances of that second job.


Any idea to fix it?
murgh
level2
level2
Posts: 232
Joined: Sat Jan 30, 2016 11:52 am

Re: Job overflow

Postby murgh » Wed Oct 19, 2016 5:07 pm

You should check if the object.JobId==nil before issuing a CreateJob for the object. That way it will issue the job only once.
neoxes
level1
level1
Posts: 29
Joined: Mon Aug 26, 2013 10:49 am

Re: Job overflow

Postby neoxes » Wed Oct 19, 2016 7:01 pm

murgh wrote:You should check if the object.JobId==nil before issuing a CreateJob for the object. That way it will issue the job only once.


Uhm... It doesn't work if I want to create two different jobs.
Let's assume I already created a Job_A that still have to be completed, if I met the condition to create Job_B, then object.JobId will not be nil and Job_B is skipped.

I made a Water Dispenser who needs water and paper cups to be refilled, this is my solution (for now):

Code: Select all

function Update(dt)
   
   -- check for water
   if this.waterLeft <= 0 then
      -- fill dispenser
      if this.refillingWater then
      else
         this.refillingWater = true
         this.CreateJob("FillDispenserWater")
      end
   end
   
   -- check for cups
   if this.Slot1.i < 0 or this.cupsLeft == 0 then
      -- fill dispenser
      this.cupsLeft = 0
      if theCups then
         theCups.Delete()
      end
      theCups = nil
      if this.refillingCups then
      else
         this.refillingCups = true
         this.CreateJob("FillDispenserCups")
      end
   else
      if theCups then
      else
         theCups = getObject("PaperCup",1,this.Slot1.i)
      end
      theCups.SubType = math.ceil(4*this.cupsLeft/maxCups)
      theCups.Tooltip = "Contents Paper Cup x " .. this.cupsLeft
   end
......


Code: Select all

function JobComplete_FillDispenserWater()
   this.waterLeft = maxWater
   EmptyBottle = Object.Spawn("WaterBottleEmpty",this.Pos.x,this.Pos.y)
   if this.Or.x == -1 or this.Or.x == 1 then
      EmptyBottle.ApplyVelocity(this.Or.x*3*randpx(),6*randpx() - 3,true)
   else
      EmptyBottle.ApplyVelocity(6*randpx() - 3,this.Or.y*3*randpx(),true)
   end
   this.refillingWater = false
end

function JobComplete_FillDispenserCups()
   theCups = Object.Spawn("PaperCup",this.Pos.x,this.Pos.y)
   theCups.Loaded = true
   theCups.CarrierId.i = this.Id.i
   theCups.CarrierId.u = this.Id.u
   this.Slot1.i = theCups.Id.i
   this.Slot1.u = theCups.Id.u
   this.cupsLeft = maxCups
   this.refillingCups = false
end
murgh
level2
level2
Posts: 232
Joined: Sat Jan 30, 2016 11:52 am

Re: Job overflow

Postby murgh » Thu Oct 20, 2016 9:50 am

Well if Job_A has to be completed before Job_B can be done, then use a little boolean:

Code: Select all

...
this.jobAcompleted=false
this.CreateJob('Job_A')
...

...
function JobComplete_Job_A()
  this.jobAcompleted=true
  dothingshere
end
...

...
if this.jobAcompleted==true and otherthings==true then
   this.jobBcompleted=false
   this.CreateJob('Job_B')
...

...
function JobComplete_Job_B()
  this.JobBcompleted=true
  domorethings
...
neoxes
level1
level1
Posts: 29
Joined: Mon Aug 26, 2013 10:49 am

Re: Job overflow

Postby neoxes » Thu Oct 20, 2016 10:03 am

murgh wrote:Well if Job_A has to be completed before Job_B can be done, then use a little boolean:

Code: Select all

...
this.jobAcompleted=false
this.CreateJob('Job_A')
...

...
function JobComplete_Job_A()
  this.jobAcompleted=true
  dothingshere
end
...

...
if this.jobAcompleted==true and otherthings==true then
   this.jobBcompleted=false
   this.CreateJob('Job_B')
...

...
function JobComplete_Job_B()
  this.JobBcompleted=true
  domorethings
...


That's the way I did it :)

Thanks for replying :mrgreen:

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 9 guests