Bay 12 Games Forum

Dwarf Fortress => DF Modding => Utilities and 3rd Party Applications => Topic started by: PatrikLundell on April 27, 2018, 11:34:37 am

Title: DFHack script: The Librarian
Post by: PatrikLundell on April 27, 2018, 11:34:37 am
The Librarian is a script for viewing the contents of your library (actually everything present in the Stocks screen).
The scripts provides 5 views of the works:
- Main view: Everything. It can be filtered on category and whether works have any references.
- Scientific view: Indicator of which scientific topics the works cover, as well as listing of works per category.
- Values view: As the scientific view, but for values, with all values/strength combinations accessible.
- Authors view: Lists all your authors who have works in the fortress, as well as those works.
- Interactions view: Show all works containing interactions (i.e. The Secret of Life and Death in vanilla).
- The scientific and Values views also lists all works outside of the fortress in the selected category, which might give you ideas for which works to try to "acquire"...
- All pages also provide some basic details on the currently selected work, and in the case of a local work, also a further list of all the actual books (there may be multiple copies) with a number of their flags (Original/Copy, Forbidden, Dump, Trader, and In Inventory), with the ability to toggle the Forbidden, Dump, and Trader flags.
- A 'zoom to book' command allows you to go to a particular book location in the fortress. Note that this sub view is not intended to be playable, as there are known issued with that, which implies there are probably unknown ones as well. Return to The Librarian with the 'O'ok! command when done looking around.

The script can be found on this web page: https://github.com/PatrikLundell/scripts/blob/own_scripts/librarian.lua (https://github.com/PatrikLundell/scripts/blob/own_scripts/librarian.lua). The script section of the script is copied into a "text" file as <DF>\hack\scripts\librarian.lua. This can be done either by using the "raw" selection of the page and then "save as" of the page, or through copy & paste of the script section of the page. The script is invoked from the DFHack console by typing "librarian" (without the quotes) when a fortress is active. The script is dismissed with <ESC>.

Revision History:
0.21: 2023-04-30: 0.20 was based on an old version. 0.21 is based on 0.19, with (hopefully) the same changes. Same limited testing.
0.20: 2023-04-30: Changed to Premium release. The Help key doesn't work (no keyboard support). Limited testing.
0.19: 2020-08-03: Fixed bug causing the script to blow up when no interaction books are present.
0.18: 2020-07-17: Added a crude interactions view (Secrets of Life and Death), and handled added NONE value to the Values enum.
0.17 2020-05-24: Added some info to some additional referenced contents. Introduced wrapping for Detailed lines too long to fit on the screen so they continue on subsequent lines.
0.16 2020-05-23: Adapted to changed field names.
0.15 2019-01-22: Added slightly more info for Interactions (i.e. secrets of life and death), and worked around a reference to a non existent vector index.
0.14 2018-07-14: Fixed bug indexing values.
0.13 2018-07-12: Address bug caused by entity of unknown race.
0.12 2018-05-22: Fixed bug when no authors are available.
0.11 2018-05-05: Added category counts and fixed a bug.
0.10 2018-04-28: Added a 'zoom to book' functionality.
0.9 2018-04-27. First version in this thread.

Meph has created a Librarian's Office to allow role playing to open The Librarian as well as Legends Mode in game. The workshop is described here: http://www.bay12forums.com/smf/index.php?topic=170462.msg7805879#msg7805879 (http://www.bay12forums.com/smf/index.php?topic=170462.msg7805879#msg7805879).
Note that opening Legends Mode should be done with care. Save the game before opening Legends Mode and kill DF (e.g. with the DFHack "die" command) when done, as there are still potential fatal save game corruption issues with opening Legends Mode from Fortress Mode.

This first post is intended to be updated when/if the functionality changes to reflect the current functionality without any particular change markers beyond the revision history.
Title: Re: DFHack script: The Librarian
Post by: strainer on April 29, 2018, 11:52:38 am
Fascinating tool, so much info. Woaw it shows how all the books in the world can affect the readers... we can find awesome books to go and raid ! :D
Title: Re: DFHack script: The Librarian
Post by: Leonidas on April 29, 2018, 04:35:41 pm
For me, the biggest use of this script so far has been tracking the productivity of my scholars and scribes.
Title: Re: DFHack script: The Librarian
Post by: jecowa on April 30, 2018, 03:01:00 am
Does this go in the /hack/scripts/ folder or the /hack/lua/ folder?
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on April 30, 2018, 03:13:02 am
Does this go in the /hack/scripts/ folder or the /hack/lua/ folder?
hack/scripts. Updated the first post to clarify that.
The hack/lua folder is for DFHack lua support functionality used by scripts.
Title: Re: DFHack script: The Librarian
Post by: strainer on May 01, 2018, 01:00:33 pm
Its really a peach, feels like part of the game. Ook!
Title: Re: DFHack script: The Librarian
Post by: Leonidas on May 04, 2018, 06:12:37 am
The new features are terrific, Patrik. The flag display works well, especially being able to quickly flip through the whole library. Two books in my library were forbidden, and I didn't know it. And one book, dropped by a spooked caravan, has been stuck unmovable on the surface for years. With this script, I was able to to turn off the Trader flag and retrieve it.

The zoom-and-return feature seems to be working fine this time.

A suggestion: The "Content Type" submenu would be much more useful if it showed the number of titles in each category.

I ran the script five times, and the third time I got a bunch of errors. The script still ran fine, so far as I could tell. And I can't tell why it was the third time and not any of the others. Here's the error log:
Spoiler (click to show/hide)


Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on May 04, 2018, 08:41:30 am
Found the bug (a typing error ('.' rather than ':').

New version 0.11:
- Fixed bug
- Added category counts
Title: Re: DFHack script: The Librarian
Post by: Leonidas on May 04, 2018, 03:36:56 pm
I assume that the "Trade" flag means that the book is owned by a merchant, probably available for purchase. Would it be possible to display and set the flags that designate items to be carried to the depot and made available for sale? That way, you could build a fortress where the primary export is copies of books, like some medieval monasteries.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on May 04, 2018, 05:46:04 pm
"Trader" might be intended to mean it's brought by traders. However, about half of the books infiltrators bring are marked as Trader as well, and that also goes for many visitors killed by goblins.

I don't think there's a flag for bringing things to the trade depot, but rather a task of the same kind as those stockpiles generate (but with a much higher priority, of course). Those tasks can be generated only when a caravan is inbound or at the trade depot. I'm not sure why it's harder to go through the normal trade depot selection menu than it would be to use The Librarian, especially if you use the filtering function with the name of the books you want.
Title: Re: DFHack script: The Librarian
Post by: Leonidas on May 18, 2018, 09:56:29 pm
Thanks for adding the totals on the category screen. Nearly all my books are manuals, but Legends Viewer tells me that necromancers write all sorts of things.
Title: Re: DFHack script: The Librarian
Post by: jecowa on May 18, 2018, 10:34:25 pm
Patrik, are you okay with your Librarian script being included in Lazy Newb Packs?
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on May 19, 2018, 03:44:27 am
Patrik, are you okay with your Librarian script being included in Lazy Newb Packs?
The scripts I make are intended to be used, so I definitely don't have any problem with them being distributed (or, for that matter, modified, but in those cases I'd like the modifiers to change the version number to indicate it, so versions can be told apart). It can be noted, though, that I don't follow any pack threads except PeridexisErrant's LNP, so I won't see any issues reported in those threads unless I'm alerted to them in this thread.
Title: Re: DFHack script: The Librarian
Post by: Clément on May 22, 2018, 01:45:02 pm
Hi, I tried this script a few days ago and it worked. Trying again today it does not work (same save but a little earlier since DF crashed last time for an unknown reason). I made sure I have the latest version (commit b29e3e7).

Code: [Select]
[DFHack]# librarian
E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:1697: attempt to index a nil value (field '?')
stack traceback:
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:1697: in global 'Populate_Author_Works'
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:2639: in function <E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:2638>
        [C]: in field 'on_select'
        E:\Games\Dwarf Fortress\hack\lua\gui\widgets.lua:519: in method 'moveCursor'
        E:\Games\Dwarf Fortress\hack\lua\gui\widgets.lua:475: in method 'setSelected'
        E:\Games\Dwarf Fortress\hack\lua\gui\widgets.lua:470: in method 'setChoices'
        E:\Games\Dwarf Fortress\hack\lua\gui\widgets.lua:451: in local 'fun'
        E:\Games\Dwarf Fortress\hack\lua\class.lua:98: in upvalue 'invoke_after_rec'
        E:\Games\Dwarf Fortress\hack\lua\class.lua:127: in field 'List'
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:2445: in local 'fun'
        E:\Games\Dwarf Fortress\hack\lua\class.lua:98: in upvalue 'invoke_after_rec'
        E:\Games\Dwarf Fortress\hack\lua\class.lua:127: in upvalue 'Ui'
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:3426: in global 'Show_Viewer'
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:3433: in global 'Librarian'
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:3436: in local 'script_code'
        E:\Games\Dwarf Fortress\hack\lua\dfhack.lua:562: in function 'dfhack.run_script_with_env'
        (...tail calls...)
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on May 22, 2018, 04:40:36 pm
Thanks for the report.
The bug was caused by the complete absence of authors, so an empty list was processed.
Updated to 0.12 2018-05-22.
Title: Re: DFHack script: The Librarian
Post by: Bumber on May 24, 2018, 01:38:36 am
Why are the directories in that report switching between '/' and '\'?
Title: Re: DFHack script: The Librarian
Post by: Rafatio on July 11, 2018, 07:09:22 pm
Midgame this script suddenly stopped working for me. There aren't many books yet, so I only used it once before on this fortress, worked fine just like on the previous one. Is this actually a librarian problem or should I be worried about my creatures doing things out of bounds?
(https://abload.de/img/d__spiele_peride1.10-gzs3h.png)
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on July 12, 2018, 03:29:19 am
Thanks for the error report.
Looking at the error text, I see that the index is -1, which DF uses as a null value. From other cases, creatures can be considered to be of an unknown race when they have been considered unimportant historical figures, and thus have been removed from the game (there's a world gen switch for this).
Thus, it looks like the script needs to be updated to handle the case of unknown races. I'll be back with an updated version shortly.

Edit: I've modified the script and uploaded it to Github (the link in the first post), but I can't test it since I don't have your situation.
Title: Re: DFHack script: The Librarian
Post by: Rafatio on July 12, 2018, 05:41:32 am
Thanks for the speedy fix, it's working again.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on July 12, 2018, 05:59:57 am
Thanks for testing and reporting back.
Title: Re: DFHack script: The Librarian
Post by: Meph on July 12, 2018, 08:55:03 am
Does the script open a UI ingame, a pop-up?

If yes, I could easily supply a little workshop, so that a dwarf can trigger it. Player builds the "Librarian's Office", dwarf "read up on current collection" and the script runs.

I did something similar for the script that opens legends mode.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on July 12, 2018, 09:31:12 am
Does the script open a UI ingame, a pop-up?

If yes, I could easily supply a little workshop, so that a dwarf can trigger it. Player builds the "Librarian's Office", dwarf "read up on current collection" and the script runs.

I did something similar for the script that opens legends mode.
Try ;)

It opens a view on top of DF in the same basic way gui/gm-editor does, so it's a lot larger than a single pop-up window.
If you want to create such a custom workshop you're very welcome to do so, although personally I wouldn't like to wait for it to appear, but I'm not that great on the role playing aspect.
Title: Re: DFHack script: The Librarian
Post by: Meph on July 12, 2018, 01:29:39 pm
Reactions:
Code: [Select]
[OBJECT:REACTION]

[REACTION:LIBRARIAN]
[NAME:Read the book index]
[BUILDING:LIBRARIANS_OFFICE:CUSTOM_B]

[REACTION:OPEN_LEGENDS]
[NAME:Read the legends of this world]
[BUILDING:LIBRARIANS_OFFICE:CUSTOM_L]

Onload.init:
Code: [Select]
#librarians office
modtools/reaction-trigger -reactionName OPEN_LEGENDS -command [ open-legends ]
modtools/reaction-trigger -reactionName LIBRARIAN -command [ librarian ]

entity additions:
Code: [Select]
[PERMITTED_BUILDING:LIBRARIANS_OFFICE]
[PERMITTED_REACTION:OPEN_LEGENDS]
[PERMITTED_REACTION:LIBRARIAN]

workshop:
Code: [Select]
building_librarian

[OBJECT:BUILDING]

[BUILDING_WORKSHOP:LIBRARIANS_OFFICE]
[NAME:Librarian's office]
[NAME_COLOR:7:0:1]
[BUILD_LABOR:ARCHITECT]
[BUILD_KEY:CUSTOM_SHIFT_G]
[DIM:3:3]
[WORK_LOCATION:2:2]
[BLOCK:1:0:0:0]
[BLOCK:2:0:0:0]
[BLOCK:3:0:0:0]
[TILE:0:1:32:32:234]
[TILE:0:2:32:227:32]
[TILE:0:3:32:43:32]
[COLOR:0:1:0:0:0:0:0:0:6:0:1]
[COLOR:0:2:0:0:0:7:0:1:0:0:0]
[COLOR:0:3:0:0:0:7:0:0:0:0:0]
[TILE:1:1:32:32:234]
[TILE:1:2:32:227:43]
[TILE:1:3:234:43:32]
[COLOR:1:1:0:0:0:0:0:0:6:0:1]
[COLOR:1:2:0:0:0:7:0:1:7:0:0]
[COLOR:1:3:6:0:1:7:0:0:0:0:0]
[TILE:2:1:234:32:234]
[TILE:2:2:43:227:43]
[TILE:2:3:32:43:234]
[COLOR:2:1:6:0:1:0:0:0:6:0:1]
[COLOR:2:2:7:0:0:7:0:1:7:0:0]
[COLOR:2:3:0:0:0:7:0:0:6:0:1]
[TILE:3:1:234:43:234]
[TILE:3:2:43:227:43]
[TILE:3:3:234:43:234]
[COLOR:3:1:6:0:1:7:0:0:6:0:1]
[COLOR:3:2:7:0:0:7:0:1:7:0:0]
[COLOR:3:3:6:0:1:7:0:0:6:0:1]
[BUILD_ITEM:4:STATUE:NONE:NONE:NONE][CAN_USE_ARTIFACT]
[BUILD_ITEM:1:CABINET:NONE:NONE:NONE][CAN_USE_ARTIFACT]

That's it. A little librarians office that either opens the librarian script, looking at all the books; or runs open-legends and you can read through that. :)
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on July 13, 2018, 03:20:54 am
I added a link to your post to the first page.
Title: Re: DFHack script: The Librarian
Post by: Rafatio on July 14, 2018, 10:25:06 am
I have another error, this time it's not fatal, librarian seems to work fine for what I'm doing (browse the values page to find books to forbid), but when I check back to the dfhack window later, there often is all this error text. Same fort, still playing 44.10, as unmodded as I get to claim in this subforum.
Spoiler (click to show/hide)
Always these three repeats together if it happens, but sometimes there are no errors. No idea what makes the difference.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on July 14, 2018, 11:51:04 am
Thanks for the report. I've been able to replicate the bug and fix it. It's caused by line 2635 using "- 1" rather than "- 4", so it's trying to reference a value strength that doesn't exist (they run from -3 to 3, but indices go from 1 to 7). I've fixed it and uploaded the script to the repo.
Title: Re: DFHack script: The Librarian
Post by: Rafatio on July 14, 2018, 01:22:31 pm
You're fixing these faster than I can save and reload, no red text anymore.
Title: Re: DFHack script: The Librarian
Post by: Blucher on December 05, 2018, 07:33:27 pm
This is great!  Love it!
Title: Re: DFHack script: The Librarian
Post by: Leonidas on May 23, 2020, 02:42:46 am
Is this script abandoned, Patrik? In 47.04 I'm getting a wall of red text.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on May 23, 2020, 05:39:38 am
Is this script abandoned, Patrik? In 47.04 I'm getting a wall of red text.
It's not abandoned as such, but I haven't used it for a long time, and so, haven't detected that things have failed. Yours is the first report of that... I'll take a look at it.

Edit: I've now updated it to handle that two fields changed names. However, there are probably other things that have changed that weren't caught by my check (because the fortress I used certainly didn't have all possible kinds of books).
Please report errors found (Rafatio's  report is a good example of one that allows me to find where issues are even if I don't have a book that triggers that issue). Such a report wasn't needed in this case as the failure happens immediately and in any fortress (I think), but if it only appears for a single type of book it won't be obvious.
Title: Re: DFHack script: The Librarian
Post by: Leonidas on May 23, 2020, 02:08:35 pm
And now it works again! Thanks!

Edit: I added a note in the Library wiki page about your script. As I see it, the current libraries are pretty much useless without it.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on May 24, 2020, 05:20:29 am
Added a little support for competition and art references, and introduced line fitting for Detailed contents so they continue on the next line(s) rather than disappear over the edge of the screen.
Title: Re: DFHack script: The Librarian
Post by: Fleeting Frames on May 24, 2020, 10:50:00 pm
Btw, worth mentioning I did a small fix for 43.03, posted in full here: https://dwarffortresswiki.org/index.php/User:Fleeting_Frames/librarian

Change boils down to adding functions

Code: [Select]
function base2string(inputnr)
if inputnr <= 1 then return inputnr end
return tostring(inputnr%2) .. tostring(base2string(math.floor(inputnr/2)))
end

function base2string_To_Index_Truth_Table(inputstr)
local i = 1
local ret = {}
if not inputstr then return ret end
for i = 1, string.len(inputstr) do
if(string.sub(inputstr, i, i) == "1") then
ret[i-1] = true
end
end
return ret
end

then using

Code: [Select]
if ref._type == df.general_ref_knowledge_scholar_flagst then
          for l, flag in pairs (base2string_To_Index_Truth_Table(base2string(ref.knowledge.flags))) do

rather than
Code: [Select]
if ref._type == df.general_ref_knowledge_scholar_flagst then
          for l, flag in ipairs (ref.knowledge.flags.flags_0) do

(didn't recall this thread at the time of the posting; only the github, so it doesn't contain two most recent version changes)

PS: I'd suggest adding a picture in the OP; it's honestly pretty great for larger libraries and raiding.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on May 25, 2020, 03:49:13 am
Sorry, but I fail to see what problem the convoluted code change fixes, so you'll have to explain it to me.

As far as I understand, the changed logic converts the flag data into a reverse order binary code string and then builds a sparse table containing the "1" entries as "true" in a bit + 1 table. I think that would cause the bits to be shifted one step, from a zero based indexing to a one based one, although further analysis would be needed to determine if the loops are the only usages of the indices, in which case it doesn't matter.

The original script logic relies on the fact that the data is a union, with all flags overlapping, and so it doesn't matter that we iterate over the first one (where all bits are used) rather than the one actually used, apart from accessing bits that should never be set in some cases.
Title: Re: DFHack script: The Librarian
Post by: Fleeting Frames on May 26, 2020, 12:17:57 am
43.03, the data is stored as just a number; script throws error in console due that and quits. This converts the number into something pairs can iterate over, i.e. 262144 is memory value that is = 2^18 (which pairs will complain about), but pairs({[18]=true}) works fine.

And...hm, you're right about it being off by one. I checked that example book got tossed right into geography, but it seems water cycle became "latitude climate zones". Whoops, stupid zero vs 1-based indices; ret[i-1] seems to fix that (edited on wiki).
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on May 26, 2020, 02:18:56 am
OK, if 0.43.03 just had a number there, yes, it would blow up (as it evidently did!). In 0.47.04 the overloaded fields are flag bit fields, so I don't see any need to change the script for the current DF version, as it seems your change was particular for your back ported version.
Title: Re: DFHack script: The Librarian
Post by: Leonidas on July 06, 2020, 08:40:43 am
How many books would it take to overload this script? Could it handle 10,000?
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on July 06, 2020, 11:03:14 am
Probably. It takes a significant time to handle worlds with 10000 books (a visible delay), but apart from time, memory would be the other constraint, and each book isn't using that much memory, so I'd expect slowdown to be the most problematic issue. Sorting books takes a fair bit of time (using exchange sort). Thus, it's probably more an issue of how long you're prepared to wait and how long lists you can stand scrolling through.
Title: Re: DFHack script: The Librarian
Post by: Leonidas on July 07, 2020, 10:22:12 am
So it's already looking at all the books in the world, and moving those books into my fort won't change things much. That makes sense.
Title: Re: DFHack script: The Librarian
Post by: Nopenope on July 07, 2020, 10:41:11 am
Now that GPT-3 is a thing and has a public API I wonder how hard it would be to send it the book descriptions as prompts and generate the books' contents on the fly.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on July 07, 2020, 11:59:30 am
Now that GPT-3 is a thing and has a public API I wonder how hard it would be to send it the book descriptions as prompts and generate the books' contents on the fly.
I have no idea what "GPT-3" is supposed to be, but it sounds like you want to invent stories, which isn't compatible with the purpose of the Librarian, which is to show what's there in DF, even though DF's UI doesn't display all of it.
Title: Re: DFHack script: The Librarian
Post by: Leonidas on July 16, 2020, 09:33:15 pm
Is there an efficient way to identify necromancy books? I'm shoveling books around by the hundreds, and I really don't want one to slip through and turn all my scholars into necromancers.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on July 17, 2020, 04:01:18 am
Technically yes, i.e. it's possible to detect that a book contains a secret (and all secrets are currently about life and death). If I remember correctly, the script prints that a book contains a secret (and prints the text about what taken from the book, i.e. life and death in vanilla), but the script currently doesn't contain any search filter for it.

Edit: Updated the script to provide a crude Interactions view, plus handling of the addition of NONE to the Values enum.
Title: Re: DFHack script: The Librarian
Post by: Silverwing235 on July 18, 2020, 10:07:02 am
Now that GPT-3 is a thing and has a public API I wonder how hard it would be to send it the book descriptions as prompts and generate the books' contents on the fly.
I have no idea what "GPT-3" is supposed to be, but it sounds like you want to invent stories, which isn't compatible with the purpose of the Librarian, which is to show what's there in DF, even though DF's UI doesn't display all of it.

...*ahem* If I may? You know that OpenAI dataset that didn't have its source released, because of fake news concerns? Well, this is that one's successor.
Title: Re: DFHack script: The Librarian
Post by: Stiqy on August 02, 2020, 07:27:20 am
Is this a normal error in 47.04?

https://imgur.com/fKfFEI9
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on August 02, 2020, 08:08:01 am
Is this a normal error in 47.04?

https://imgur.com/fKfFEI9
No. All such messages are indications of bugs. However, to fix bugs as they're discovered, I generally need to be able to replicate them, which means access to a save that causes it to appear, and a description of how to generate the message (i.e. what you tried to view when getting the message and how to get there [The name of the book and the view and potential filter used is probably enough in most cases]).
Title: Re: DFHack script: The Librarian
Post by: Stiqy on August 02, 2020, 03:04:31 pm
I just created the script as instructed. loaded up my fort and tried to run it with "librarian" the first time. Nothing happened except the red text.  I can share the save if it will help.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on August 03, 2020, 03:26:15 am
Thanks Stiqy.

The bug was caused by the script trying to index the first element in the empty list of books with interactions in them, which fails, of course. The bug was introduced with the latest change to the script. I've fixed the bug and uploaded the updated script to the link at the first page.
Title: Re: DFHack script: The Librarian
Post by: Stiqy on August 03, 2020, 08:41:56 am
Thanks Stiqy.

The bug was caused by the script trying to index the first element in the empty list of books with interactions in them, which fails, of course. The bug was introduced with the latest change to the script. I've fixed the bug and uploaded the updated script to the link at the first page.

You rock.
Title: Re: DFHack script: The Librarian
Post by: Leonidas on August 05, 2020, 01:26:00 am
The new Interactions view works perfectly. I suspected that I only had the one volume on life and death, but it's nice to be sure.
Title: DFHack script: The Librarian
Post by: axemangeorge on August 12, 2020, 09:38:25 am
Thanks for this awesome script!! It's so cool to peek under the hood and see the effects books can have on my oddly literate citizens!

I also really appreciate you not only making the script available, but THEN revising and bug-fixing till it works. Mad props.
Title: Re: DFHack script: The Librarian
Post by: myk on March 31, 2022, 12:36:43 pm
Is there any reason you haven't submitted this for inclusion in DFHack?
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on April 01, 2022, 02:58:22 am
Yes...

The main problem with inclusion into DFHack is that bugs can't be fixed quickly after they've been discovered (or, rather, that even if the bugs are fixed the next day, DFHack won't have a release containing the corrected version the next day), but rather when DFHack has accumulated enough changes to warrant a new release. This means it can take months or years for a corrected version to reach those who encountered the bug in the first place.

Another, lesser, reason is that Github is disgusting to work with (I do when I have to, though, such as e.g. DFHack structure mapping).

These are the main reasons I don't submit scripts for inclusion into DFHack. They don't have to be compiled into it to work (as they're scripts), so the most compelling reason to include them simply doesn't exist.

However, I'm not opposed to others including the scripts I've created (which would also include stripping them of backwards compatibility, as that's pointless when bundled with the version specific DFHack), but I'm not willing to put in that effort for something that might not even seem to be an advantage.

If someone does include scripts, I'd like to be notified so I won't be taken by surprise.
Title: Re: DFHack script: The Librarian
Post by: myk on April 04, 2022, 10:54:30 pm
I think the main benefit of distributing with DFHack is that more people have access to the script and more people discover how useful it is. Your point about DFHack releases being infrequent is valid, but it doesn't prevent people from getting bugfixes just as expediently as they do now. They can still download the latest script from GitHub and overwrite their local copy. As you said, it doesn't need to be compiled.

The question of accessibility came up when I recommended The Librarian on Reddit for discovering whether the books retrieved in a raid include any necromancer secrets. The existence of the script was news to a lot of people. If The Librarian were distributed with DFHack (or LNP), then fewer people would be struggling with problems the script has already solved.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on April 05, 2022, 02:40:47 am
People fail to find a lot of things that are in DFHack currently and thus ask for the implementation of existing functionality. Those knowledgeable enough to find the pending next version of a script on Github are probably capable of finding it as a separate script. Also, "next version" scripts sometimes won't work with the current version because the structures have changed.

However, you're free to make a Pull Request (Github gobbledigook for request to add/change something) with the script if you want to.
Title: Re: DFHack script: The Librarian
Post by: myk on April 06, 2022, 08:27:31 am
If you'd rather maintain the script outside of the DFHack tree, then I'm happy staying with the status quo. I wouldn't want to fork the script and create two places where fixes have to be made!
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on April 07, 2022, 03:17:51 am
If it's moved it will be moved, not duplicated, so current repositories wouldn't be maintained.

It also remains to be seen how DFHack survives the Premium release, as the changed UI will mess up everything that has a UI.
Title: Re: DFHack script: The Librarian
Post by: Salmeuk on April 07, 2022, 01:28:00 pm

It also remains to be seen how DFHack survives the Premium release, as the changed UI will mess up everything that has a UI.

don't scare me patrik. don't scare me
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on April 08, 2022, 02:32:51 am
I believe there's a good chance DFHack itself will adapt, but the UI changes of DF with its various grids will result in the need for some serious work by competent people to make UI functionality work with that framework. I don't know if it will be possible to retain the script/code facing functionality mostly unchanged, or if it will have to be replaced with something that has to be adapted to use different logic.
I would expect "simple" things like popup windows and general dialog boxes to be able to work roughly the same, but anything that defines dimensions and placement will have to change, either in syntax or in use.

The really scary part is the splitting of Premium and Classic UI. If it is done just using different looking widgets that function the same and take up the same space, that's probably not an issue, but if the implementations are functionally different it can be really bad.

Sorry Salmeuk, you didn't want to be scared, but I think there's a reason to be worried on the UI side of things.

To clarify: I'm in favor of a good UI, so I support the UI rework in principle, but I'm not in favor of doing the same UI work twice just for the sake of retaining a Classic/Premium split. Two different UI tile sets/widget looks is perfectly fine, though. Having said that, a UI that doesn't support key shortcuts is NOT good, regardless of how shiny it looks, and I continue to worry about it being put off until never.
Title: Re: DFHack script: The Librarian
Post by: Nopenope on April 08, 2022, 02:36:24 pm
There's a good chance that Toady won't want to bother with two separate and functionally different UIs (for good reason and probably exactly the same reason as DFHack maintainers wouldn't). It's impossible to know for sure of course but my read has always been that DF Premium would be DF Classic + audio and a nice tileset (and perhaps Steam achievements), and nothing more.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on April 08, 2022, 05:00:54 pm
He's said he want the widget thingies to be the same underneath the surface, but there seem to be issues causing trouble.

If it was my decision I'd fall back to using the same UI widgets for both version if it isn't possible to skin them differently, for whatever reason. However, that hinges on there not being something contractual blocking it (such as e.g. all artist work belonging to the Premium version exclusively).
Title: Re: DFHack script: The Librarian
Post by: Asdfe on January 30, 2023, 10:54:41 pm
Any chance we'll see an update for Steam? Otherwise, is there anything similar to it? I've got a fort with nearly 700 books, and ideally I'd like to dump them all to a spreadsheet so I can sort through them for stuff that stands out like chronicles, biographies, dictionaries, encyclopedias, and etc.
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on January 31, 2023, 03:26:25 am
I don't know.

I will start to investigate DFHack related things once DFHack supports the Classic version (or the Itch.io version once DF has restored keyboard support).
Since the script only uses "normal" UI functionality (as opposed to trying to create overlays) it ought to be reasonably straightforward to update it, assuming the DFHack mapping of data has been updated.

Edit:
DFHack now supports Classic, and after fixing an interface profile change, I'm now stuck on DF itself currently no longer supporting any Help key binding (to which the help screen is bound). It ought to be restored when keyboard support is restored, at which point it would be useful to continue.
Title: Re: DFHack script: The Librarian
Post by: fricy on April 29, 2023, 01:19:41 pm
I don't know.

I will start to investigate DFHack related things once DFHack supports the Classic version (or the Itch.io version once DF has restored keyboard support).
Since the script only uses "normal" UI functionality (as opposed to trying to create overlays) it ought to be reasonably straightforward to update it, assuming the DFHack mapping of data has been updated.

Edit:
DFHack now supports Classic, and after fixing an interface profile change, I'm now stuck on DF itself currently no longer supporting any Help key binding (to which the help screen is bound). It ought to be restored when keyboard support is restored, at which point it would be useful to continue.
You may find some help with that. (https://github.com/DFHack/dfhack/issues/3313)
Title: Re: DFHack script: The Librarian
Post by: PatrikLundell on April 30, 2023, 02:59:08 am
I've managed to update the script to mostly work with the Premium release. The help key doesn't work as the keyboard support was removed. A work around to bind it directly to the question mark was introduced, and while it doesn't work, it also doesn't prevent the script from being parsed.

Extremely limited testing on a save with books in it. I didn't see any problems in that very limited test. The script may be based on an old version, as the revision was old, for some strange reason.
The contents of the link on the first page has been updated.

Edit: The updated version was based on an old version. 0.21 is based on 0.19, with the same (?) limited set of changes. The help key still doesn't work.
Title: Re: DFHack script: The Librarian
Post by: myk on April 30, 2023, 11:01:20 am
The help key doesn't work as the keyboard support was removed. A work around to bind it directly to the question mark was introduced, and while it doesn't work, it also doesn't prevent the script from being parsed.

For the record, this is the same decision we made for gui/gm-editor. The help hotkey was changed from reacting to key="HELP" to reacting to key="STRING_A063". I have a PR open for g_src that adds CUSTOM_CTRL_SLASH as a standard interface key that could replace HELP.