Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Dfhack: how to remove job object properly  (Read 1371 times)

Raidau

  • Bay Watcher
    • View Profile
Dfhack: how to remove job object properly
« on: January 06, 2015, 06:26:40 am »

I want to write a function which properly removes issued job from the game.

Currenly i have written this, seems to work and it doesnt cause crashes on save and world unloading, but im afraid there are some additional references to a job in DF memory

This function is called when list prompt is cancelled, and works only if the job is the last in job list.

Dont pay attention to debug lines

Code: [Select]
function() --on cancel
print ("on cancel")
print ("holder building = "..tostring(dfhack.job.getHolder(job)))

local function get_last_job ()

local cur_job = df.global.world.job_list
while cur_job.next ~=nil do
print ("job list next checked")
cur_job = cur_job.next
end
return cur_job.item
end

if get_last_job() == job then
print ("job is last in list")

for a,b in pairs (dfhack.job.getHolder(job).jobs) do
if b == job then
dfhack.job.getHolder(job).jobs:erase(a)
job.general_refs:erase(0)
break
end
end

job.list_link.prev.next = nil
job.list_link:delete()
job:delete()

end

--dfhack.job.printJobDetails(job)
--job.flags.item_lost = true]]
end
« Last Edit: January 06, 2015, 06:28:33 am by Raidau »
Logged
Marital status manipulator
Custom item descriprions
Natural Balance Mod (2013-2015) development suspended...

rrauenza

  • Escaped Lunatic
    • View Profile
Re: Dfhack: how to remove job object properly
« Reply #1 on: April 16, 2017, 07:08:53 pm »

For future reference, I cobbled together some code here http://www.bay12forums.com/smf/index.php?topic=163778.msg7424924#msg7424924 to remove a bunch of FellTree jobs.

Thanks for posting yours -- it got me down the right path and led me to the code in advfort.lua.

Logged