Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: relations-indicator [DFHack lua script] 1.14  (Read 2502 times)

Saiko Kila

  • Bay Watcher
  • Dwarven alchemist
    • View Profile
Re: relations-indicator [DFHack lua script] 1.13
« Reply #15 on: August 02, 2018, 02:58:12 pm »

Hi, I get a problem sometimes, when the script relations.indicator freezes the game. Technically it doesn't freeze it (I can still run scripts from console), it just disables keyboard input or something  in the main window, and to exit game I need to "die".

The problem is with lines 323 and 324:
Code: [Select]
323:                    if text:find("STERILE") or
324:                       text:find("OPPOSED_TO_LIFE") then
The error thrown is:
Spoiler (click to show/hide)

It seems that sometimes (on some units) the value returned by iterator is not string type but userdata type, which doesn't have this method (i.e. find).

I changed the lines to these:
Code: [Select]
323:                    if string.find(tostring(text),"STERILE") or
324:                       string.find(tostring(text),"OPPOSED_TO_LIFE") then

The conversion (tostring) is important. I don't know if it works as intended now, but at least it won't "freeze" my game anymore.
Logged

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: relations-indicator [DFHack lua script] 1.13
« Reply #16 on: August 02, 2018, 03:12:24 pm »

Oh, that.

I'm aware of the bug...Was wondering if it would crop up.

See, the thing is: "text" is stored not as a string, but as value pair with text.value being the actual string. (I guess calling tostring() on it also works).

Why didn't I fix it, then?

Because I only encountered it in the custom changed compile of dfhack I did - it didn't throw the error, for the same unit, in normal 43.03 compile *shrug*.

For future reference, all scripts with my gui/indicator-screen close themselves on "?" as that is not implemented (on purpose).

Tested it being broken with a handy save on 44.10, my already-done fix for that working, and uploaded the fix (1.14). But feel free to keep using your old one.
« Last Edit: August 02, 2018, 03:16:44 pm by Fleeting Frames »
Logged

Saiko Kila

  • Bay Watcher
  • Dwarven alchemist
    • View Profile
Re: relations-indicator [DFHack lua script] 1.13
« Reply #17 on: August 02, 2018, 03:46:28 pm »

For future reference, all scripts with my gui/indicator-screen close themselves on "?" as that is not implemented (on purpose).

OK, pressing "?" kills the script and returns control. May be useful if some other issue shows up.

BTW, it's a nitpick but you are referring to the gui script (here and in the original post) as "indicator-screen", but the relations-indicator uses "indicator_screen"... I initially named the script as "indicator-screen.lua", and wondered why this didn't work :P
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: relations-indicator [DFHack lua script] 1.13
« Reply #18 on: August 02, 2018, 05:51:00 pm »

devel/pop-screen will also dismiss any screen that's open (note that if you run this when just one screen is open, it will quit DF). But that will work even if the screen doesn't implement a safety feature itself (no need for "die").

Edit:
See, the thing is: "text" is stored not as a string, but as value pair with text.value being the actual string. (I guess calling tostring() on it also works).
It's actually a pointer, and .value is equivalent to dereferencing the pointer in C++.

Note that tostring() will NOT work as you expect - it will produce something like "<string: 0x1286737>", which is a string representation of the pointer, not the actual value. tostring() doesn't do anything special for different types of pointers (e.g. pointers to strings).

Quote
Because I only encountered it in the custom changed compile of dfhack I did - it didn't throw the error, for the same unit, in normal 43.03 compile *shrug*.
Usually non-pointers don't change to pointers. But 0.43.03 is ancient enough that maybe something else changed.


Edit 2: late here, but
i love the idea of this, but when i put the relations indicator and indicator screen luas into the right places, i came across a problem - the onmapload_extra.init doesn't exist, so i popped the keybinds into the dfhack.init which seemed to work.
In general, you could just create the file.
Fleeting Frames: keybinding commands affect the whole DF session, so they don't require a map to be loaded. Sure, the commands being run may require a map, but "keybinding" itself doesn't care at all. You even provided contexts for all of them, which prevents them from running before a map is loaded, which is good. But telling people to add them to dfhack.init would be better - that's where all of the default keybindings are.
(Oh, and the "_extra" suffix isn't necessary either - anything matching "onMapLoad*.init" or "onLoadMap*.init" will work.)
« Last Edit: August 02, 2018, 06:03:11 pm by lethosor »
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.

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: relations-indicator [DFHack lua script] 1.13
« Reply #19 on: August 02, 2018, 09:55:19 pm »

@string: Hm, *tests*, right you are. How foolish and optimistic was I to merely guess!

(For those who don't know what is dereferencing a pointer, it means .value outputs the actul text (tested).)

@keybinds: figured it'd save processor cycles to have them in onmapload_init, but there's not much difference. Corrected.

@Saiko Kila: Huh. So I did. Sorry about that.

lethosor

  • Bay Watcher
    • View Profile
Re: relations-indicator [DFHack lua script] 1.13
« Reply #20 on: August 03, 2018, 09:24:21 am »

(For those who don't know what is dereferencing a pointer, it means .value outputs the actul text (tested).)
(Technically it doesn't have to be strings - there are pointers to integers and other things too, although only pointers to primitive types like strings and integers require ".value" to get to the value. Basically, primitive pointers are represented in Lua as a structure with one field, "value", which is the value at the address pointed to.)
Quote
@keybinds: figured it'd save processor cycles to have them in onmapload_init, but there's not much difference. Corrected.
dfhack.init runs in a separate thread so it doesn't delay startup. onLoad*.init files don't. Really, though, "keybinding" commands themselves are very fast. The only noticeably slow thing in the default dfhack.init that I know of is enabling plugins which use vmethod hooks (e.g. ones that draw/intercept input on existing screens, like "search"), because that requires patching read-only memory and can be slow.
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.
Pages: 1 [2]