This code
local function fusion(reaction,unit,input_items,input_reagents,output_items,call_native)
local tbl={}
for k,u in ipairs(df.global.world.units.active) do
local name=dfhack.TranslateName(dfhack.units.getVisibleName(u))
if name=="" then name="?" end
if (df.global.gamemode==1 and u.race==df.global.world.units.active[0].race) or (df.global.gamemode==0 and dfhack.units.isDwarf(u) and dfhack.units.isCitizen(u)) then table.insert(tbl,{name,nil,u}) end
end
table.sort(tbl,function(a,b) return getPowerLevel(a[3])>getPowerLevel(b[3]) end)
script.start(function()
local unitsToFuse={}
local f=function(name,C)
table.insert(unitsToFuse,C[3])
script.mkresume(true)
end
repeat
dialog.showListPrompt("Unit Selection","Choose first Saiyan to fuse (by power level)",COLOR_WHITE,tbl,f)
script.wait()
dialog.showListPrompt("Unit Selection","Choose second Saiyan to fuse (by power level)",COLOR_WHITE,tbl,f)
script.wait()
if unitsToFuse[1]==unitsToFuse[2] then unitsToFuse[1]=nil unitsToFuse[2]=nil unitsToFuse={} end
until unitsToFuse[1] and unitsToFuse[2] and unitsToFuse[1]~=unitsToFuse[2]
fuseUnits(unitsToFuse[1],unitsToFuse[2])
end)
call_native.value=false
end
Produces this error
...\Dwarf Fortress\Mods\Dragon Ball\hack\lua\gui\script.lua:46: Not in a gui scr
ipt coroutine.
stack traceback:
[C]: in function 'error'
...\Dwarf Fortress\Mods\Dragon Ball\hack\lua\gui\script.lua:46: in function 'getinst'
...\Dwarf Fortress\Mods\Dragon Ball\hack\lua\gui\script.lua:68: in function 'mkresume'
...Fortress\Mods\Dragon Ball/data/save/region5/raw/init.lua:277: in function 'on_select'
...Dwarf Fortress\Mods\Dragon Ball\hack\lua\gui\dialogs.lua:193: in function 'on_submit'
...Dwarf Fortress\Mods\Dragon Ball\hack\lua\gui\widgets.lua:576: in function 'submit'
...Dwarf Fortress\Mods\Dragon Ball\hack\lua\gui\widgets.lua:588: in function 'onInput'
...y Games\Dwarf Fortress\Mods\Dragon Ball\hack\lua\gui.lua:472: in function 'inputToSubviews'
...Dwarf Fortress\Mods\Dragon Ball\hack\lua\gui\dialogs.lua:224: in function <...Dwarf Fortress\Mods\Dragon Ball\hack\lua\gui\dialogs.lua:217>
[C]: in ?
The error says that this:
local f=function(name,C)
table.insert(unitsToFuse,C[3])
script.mkresume(true)
end
Is not a gui script coroutine.
I'm not sure why. I've tried 5 different completely hackish solutions (none of which I'm proud of), culminating in this:
local function fusion(reaction,unit,input_items,input_reagents,output_items,call_native)
local tbl={}
for k,u in ipairs(df.global.world.units.active) do
local name=dfhack.TranslateName(dfhack.units.getVisibleName(u))
if name=="" then name="?" end
if (df.global.gamemode==1 and u.race==df.global.world.units.active[0].race) or (df.global.gamemode==0 and dfhack.units.isDwarf(u) and dfhack.units.isCitizen(u)) then table.insert(tbl,{name,nil,u}) end
end
table.sort(tbl,function(a,b) return getPowerLevel(a[3])>getPowerLevel(b[3]) end)
local unitsToFuse={}
local f=function(name,C)
end
repeat
script.showListPrompt("Unit Selection","Choose first Saiyan to fuse (by power level)",COLOR_WHITE,tbl,function() table.insert(unitsToFuse,C[3]) local inst = getinst() return curry(invoke_resume, inst, inst.gen, false) --[[yeah I had to make it an in-line function to work... but it still doesn't]] end)
script.showListPrompt("Unit Selection","Choose second Saiyan to fuse (by power level)",COLOR_WHITE,tbl,function() table.insert(unitsToFuse,C[3]) local inst = getinst() return curry(invoke_resume, inst, inst.gen, false) end)
if unitsToFuse[1]==unitsToFuse[2] then unitsToFuse[1]=nil unitsToFuse[2]=nil unitsToFuse={} end
until unitsToFuse[1] and unitsToFuse[2] and unitsToFuse[1]~=unitsToFuse[2]
fuseUnits(unitsToFuse[1],unitsToFuse[2])
call_native.value=false
end
Combined with editing gui.scripts from this:
function showListPrompt(title, text, tcolor, choices, min_width, filter)
dlg.ListBox{
frame_title = title,
text = text,
text_pen = tcolor,
choices = choices,
frame_width = min_width,
with_filter = filter,
on_select = mkresume(true),
on_cancel = mkresume(false),
on_close = qresume(nil)
}:show()
return wait()
end
to this:
function showListPrompt(title, text, tcolor, choices, on_select, min_width, filter)
dlg.ListBox{
frame_title = title,
text = text,
text_pen = tcolor,
choices = choices,
frame_width = min_width,
with_filter = filter,
on_select = on_select,
on_cancel = mkresume(false),
on_close = qresume(nil)
}:show()
return wait()
end
And none of it's working.
Am I misunderstanding some basic aspect of
the code? The example given is too basic for me to work with, given what I'm doing. Reading the prompts reveals that they are apparently only capable of resuming the script and showing the user various prompts that do nothing, so it's not really useful. Am I overcomplicating asking for two inputs?