Bay 12 Games Forum

Dwarf Fortress => DF Modding => Utilities and 3rd Party Applications => Topic started by: Metallion on March 16, 2015, 04:21:11 pm

Title: DFHack: LUA woes
Post by: Metallion on March 16, 2015, 04:21:11 pm
I've a script in the hack/scripts (add-syndromes) directory that require a file (syndrome-util) in the hack/lua directory, which in turn requies another file (utils) in the hack/lua directory.  When I try to run add-syndromes, I get the error:

...workDF V6.2\Dwarf Fortress\hack\scripts/add-syndrome.lua:6: attempt to call field 'invert' (a nil value)
stack traceback:
        ...workDF V6.2\Dwarf Fortress\hack\scripts/add-syndrome.lua:6: in main chunk
        (...tail calls...)

I've confirmed that invert is a function defined in utils.lua.

What am I doing wrong?
Title: Re: DFHack: LUA woes
Post by: Putnam on March 16, 2015, 05:20:08 pm
Lua, not LUA.

It's trying to call "invert" rather than "utils.invert".
Title: Re: DFHack: LUA woes
Post by: Metallion on March 16, 2015, 06:48:19 pm
I'm afraid that's not it.  I should have quoted the code:

--usage: syndromeUtil.ResetPolicy.DoNothing, syndromeUtil.ResetPolicy.ResetDuration, etc
ResetPolicy = ResetPolicy or utils.invert({
"DoNothing",
"ResetDuration",
"AddDuration",
"NewInstance"
})

(Please note I take no credit for this code!)
Title: Re: DFHack: LUA woes
Post by: Putnam on March 16, 2015, 06:57:45 pm
Did you just copy the code from 0.40.24 to 0.34.11? I'm not sure if that'll work. utils.invert wasn't added until later.
Title: Re: DFHack: LUA woes
Post by: Metallion on March 16, 2015, 07:39:24 pm
That may be it.  I'll see if the latest version of DFHack works with MDF.  Thanks.
Title: Re: DFHack: LUA woes
Post by: lethosor on March 16, 2015, 07:56:51 pm
utils.invert was added in DFHack 0.40.08-r1: https://github.com/DFHack/dfhack/commit/0db0244d08e69eb36c0f31700c76b2de83fbc4ef
You could easily implement that function in your script, though:
Code: [Select]
function invert(tab)
    local result = {}
    for k,v in pairs(tab) do
        result[v]=k
    end
    return result
end