Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: DFHack: LUA woes  (Read 1581 times)

Metallion

  • Bay Watcher
    • View Profile
DFHack: LUA woes
« 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?
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack: LUA woes
« Reply #1 on: March 16, 2015, 05:20:08 pm »

Lua, not LUA.

It's trying to call "invert" rather than "utils.invert".

Metallion

  • Bay Watcher
    • View Profile
Re: DFHack: LUA woes
« Reply #2 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!)
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack: LUA woes
« Reply #3 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.

Metallion

  • Bay Watcher
    • View Profile
Re: DFHack: LUA woes
« Reply #4 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.
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack: LUA woes
« Reply #5 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
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.