Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - lethosor

Pages: 1 ... 43 44 [45] 46 47 ... 268
661
Utilities and 3rd Party Applications / Re: DFHack 0.44.12-r2
« on: February 16, 2019, 02:53:59 pm »
If print(buildingID) is printing garbage, that's not your fault. (Can you give an example?) Also, is eventful.eventType.BUILDING equal to 5?

662
Utilities and 3rd Party Applications / Re: DFHack 0.44.12-r2
« on: February 16, 2019, 02:31:21 pm »
Not seeing an obvious reason, but I'm not familiar with eventful. What does the 10 argument mean?

663
Utilities and 3rd Party Applications / Re: DFHack 0.44.12-r2
« on: February 13, 2019, 06:37:00 pm »
Almost certainly slower if you're running the loop more than once. Maybe a table of types you know have the field you want, indexed by the type so you don't have to do a linear scan, would work and be cleaner than an if statement chain.

664
Utilities and 3rd Party Applications / Re: DFHack 0.44.12-r2
« on: February 13, 2019, 03:31:07 pm »
Worth noting that pcall will be significantly slower than handling individual types, if that's something you can do, so don't use the pcall approach in anything performance-intensive. I assume there are good reasons for not returning nil for nonexistent fields, although I wasn't around when that decision was made - it's probably better for those accesses to fail early instead of silently succeeding for typos and such.

665
Utilities and 3rd Party Applications / Re: DFHack 0.44.12-r2
« on: February 13, 2019, 01:08:35 pm »
To be clear, you don't mean actually crashing, right? Crashes aren't possible to prevent after the fact.

pcall takes a function to call (optionally with arguments) and returns a boolean representing whether an error occurred, followed by the function's return values or the error. So something like this should work:
Code: [Select]
field_exists = pcall(function() return object.some_field end)
Something like this ought to be in utils.lua or exposed through the C++/Lua bridge...

666
Utilities and 3rd Party Applications / Re: DFHack Job Triggers
« on: February 13, 2019, 01:03:36 am »
Worth noting that restarting DFHack is usually overkill. In this case, you might be able to get by with "reload eventful" at the console and/or "reload('plugins.eventful')" in Lua. For most scripts in general (if they're not messing with global DFHack state outside of their own state), clearing or deleting dfhack.script_environment('script_name') will work.

667
Utilities and 3rd Party Applications / Re: DFHack 0.44.12-r2
« on: February 09, 2019, 07:37:27 pm »
Is there a way to access the plant raw strings like we can access the creature raw strings? I figure the plant_raw.anon_1 is the list of strings similar to creature_raw.raws, but it's all userdata entries.
Yup:
Code: [Select]
[lua]# ~df.reinterpret_cast('string',df.plant_raw.find(0).anon_1[0])
<string: 0x112e5b010>
value                  = [NAME:single-grain wheat]
Obviously don't use this in a script, but I'll add a name to the xml files.

668
Utilities and 3rd Party Applications / Re: DFHack 0.44.12-r2
« on: February 01, 2019, 06:29:15 pm »
1. If I tie a save file function into the onUnload event should I save to current or the region save file?
That is probably too late to access any world data. It might fire after DF copies the current folder to the region folder too. If you can't do it any earlier, you might have to save to the region folder, but even that name might not be accessible any more. I would experiment with saving something to current and see where that ends up.
Quote
2. For the GUI stuff is there a way to distinguish between the arrow keys, numpad keys, and numbers for the keys or are they all treated the same?
You should be using DF's key IDs, which depend on the keybindings that are set. Use STANDARDSCROLL_UP/DOWN. when you're scrolling through a list and CURSOR_UP/etc. when you're moving a cursor (like the X on the map) around the screen. DF and DFHack don't have a way to distinguish between arrow keys and number keys once they've been translated to IDs.
Quote
3. Are unit or item ids every reused while playing? I'm guessing historical unit ids are unique, but several of my scripts assume unit ids are also unique.
Don't know about this. They might potentially be reused in different forts in the same world, but I doubt it. Histfig IDs are unique (I'm pretty sure those are the IDs used in the unit-X.dat files in the save folders). If you're concerned, you could tack on the fort/site ID as well for whatever you're doing.
Quote
4. There are a lot of great functions available in dfhack.units and the other dfhack.BLANK stuff. If I was interested in porting some of my functions that I currently use that I think other people might find useful from my lua functions to built in functions how should I go about that? (I am familiar with writing C code so that isn't an issue)
Files that need to be changed:
https://github.com/DFHack/dfhack/blob/master/library/modules/Units.cpp (for dfhack.units; other files for other modules, of course)
https://github.com/DFHack/dfhack/blob/master/library/include/modules/Units.h (again, depends on the module)
https://github.com/DFHack/dfhack/blob/master/library/LuaApi.cpp (usually just a WRAP macro works)
https://github.com/DFHack/dfhack/blob/master/docs/Lua%20API.rst
Ideally the changelog too, but that's not as important.

Quote
EDIT: Another question I forgot, is there an easy way to detect when custom view screens "turn on and off". My detailed unit viewer currently let's you access the gui/gm-editor for the unit directly for it, but if you change anything in the editor you have to exit out of the viewer and start it again. I was hoping to be able to automatically reload my viewer when exiting the editor but my tests with screen:onShow haven't been successful
Looking at https://github.com/DFHack/dfhack/blob/master/plugins/manipulator.cpp, I think the logic() vmethod gets called periodically when the screen is active (render() should too - logic() might be onIdle() in higher Lua APIs, but render() or onRender() or whatever you're using should work for your purpose). Your screen could set a flag when it opens the screen, and the next time logic() or render() are called, it could refresh itself and reset the flag. "do_refresh_names" is the flag manipulator uses. Does that help?
Quote
EDIT2: Do we know the speed change calculations for calculating gait speed based on strength/agility? I wrote a small script to calculate the kph value of a unit based on the gaits file in the raws but it doesn't takes into account and modifiers (the current dhack.units.computeMovementSpeed always returns 0)
Not seeing anything in the XML files about it, sorry. Someone else might know.

669
Utilities and 3rd Party Applications / Re: DFHack 0.44.12-r2
« on: January 28, 2019, 09:04:32 pm »
We actually submitted a bug report to GitHub about that (it's because the scripts submodule uses a relative URL now, ../../DFHack/scripts). They know it's broken but it's presumably not a high-priority issue.

670
Utilities and 3rd Party Applications / Re: DFHack 0.44.12-r2
« on: January 19, 2019, 11:51:38 am »
Yes, sorry. I meant if the game saves and moves an out of date dat file then updates the dat file in the data/save/current directory but crashes before that can get moved to the data/save/regionX folder.
If the game crashes, the updated .dat file shouldn't get copied to the regionX folder. That's how the current persistent API works as well.

Quote
For normal saves this isn't an issue since there is the ON_WORLD_UNLOAD thing, and for autosaves it shouldn't be an issue since they happen at specific times and I can always make sure to get the updated dat file in the /current directory in the correct order. But quicksaves aren't predictable. Luckily it is easy enough to hook into the quicksave script and just make sure that the dat file is updated in the correct order.
Keep in mind that the quicksave script doesn't run on "normal" autosaves so you won't be able to detect those. edit: I guess you can use the fact that autosave times are fixed, yeah.

Again, I'm saying you should write to data/save/current/foo.dat whenever something changes, and you will be fine. You don't need to worry about detecting save events at all. Granted, if you need to write to disk a lot (as in multiple times a second), it would be better to detect saves, and writing only periodically could risk saving slightly stale data. As part of BenLubar's persistent JSON PR, I'll try to make sure scripts have a way to access the save events as well as plugins. But for non-intensive use, you don't have to detect save events.

671

IIRC, it's new version of DFhack. IIRC, there is no 32 bit version, and without it some things will end up bonklers.
EDIT: Whoops, no, it just doesn't works on XP, but haves 32 bit version. Then...? Launcher?  :P
The launcher is 64bit. In theory you can play the mod with a 32bit version of DF, but I don't know if there even is a dfhack version for 32bit with all utilities.
There is absolutely a 32-bit version of DFHack: https://github.com/dfhack/dfhack/releases
TWBT, however, is 64-bit-only: https://github.com/mifki/df-twbt/releases

672
DF General Discussion / Re: PeridexisErrant's DF Starter Pack
« on: January 15, 2019, 09:55:25 pm »
From the first post of this thread
...
Besides the official download page on DFFD (above), /u/Hecknar maintains df.wicked-code.com, which mirrors every release since 0.40.01!
...
Looks like it has 0.44.09 to me (although I haven't downloaded it myself)

673
Utilities and 3rd Party Applications / Re: DFHack 0.44.12-r2
« on: January 11, 2019, 08:31:38 pm »
If a crash happens "between the two" what? If a crash happens while saving, it should only affect files in the current folder - that's how DF is designed, to cut down on corruption. A crash when moving files into the region folder is exceptionally unlikely.

674
Utilities and 3rd Party Applications / Re: DFHack 0.44.12-r2
« on: January 11, 2019, 07:56:16 pm »
I found I had to load from the main world folder (not /data/save/current) even though I could save to either.
Oh, sorry, I thought that part was obvious. The current folder gets cleared after saving, after its contents are copied into the region folder. Writing directly to the region folder will lead to incorrect behavior if DF quits without saving.

675
You could probably have it track which unit is selected in the map, then open a unit list screen by triggering the appropriate key (which might require backing out of menus with Gui::resetDwarfmodeView() first) and proceed from there. That wouldn't necessarily leave the unit selected in the map, but that's probably okay.

Pages: 1 ... 43 44 [45] 46 47 ... 268