Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 176 177 [178] 179 180 ... 244

Author Topic: DFHack 50.14-r1.1  (Read 888974 times)

Rinin_Rus

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2655 on: October 27, 2020, 07:04:52 am »

Is it possible to receive enum names in Lua?

Right now i'm making dictionary (table?)
Code: [Select]
Dict = {
    Socialize = df.need_type.Socialize,
    DrinkAlcohol = df.need_type.DrinkAlcohol,
    PrayOrMeditate = df.need_type.PrayOrMeditate,
    ...
}
Does any other way exist to access enum names, and list all enum values? Because such dictionary will require future maintenance. It's not like we have DF updates too often, but still.
Logged
He has a lot of willpower,  but he has very little linguistic ability

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2656 on: October 27, 2020, 07:52:19 am »

Is it possible to receive enum names in Lua?

Right now i'm making dictionary (table?)
Code: [Select]
Dict = {
    Socialize = df.need_type.Socialize,
    DrinkAlcohol = df.need_type.DrinkAlcohol,
    PrayOrMeditate = df.need_type.PrayOrMeditate,
    ...
}
Does any other way exist to access enum names, and list all enum values? Because such dictionary will require future maintenance. It's not like we have DF updates too often, but still.
df.need_type
  • will return the string you're after ("Socialize", "DrinkAlcohol", etc.), so yes, the functionality is build into the way the enum types are defined in the structures, providing a standard way to get at them.
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2657 on: October 27, 2020, 10:36:07 am »

Since the forum software messed up the formatting, what Patrik posted was
Code: [Select]
df.need_type[x]

DF enums are exposed to Lua as a bidirectional map - here's some examples from the lua interpreter:
Code: [Select]
[lua]# ~df.need_type[0]
Socialize
[lua]# ~df.need_type.Socialize
0
[lua]# ~df.need_type['Socialize']
0

I guess this is another thing that is a bit lacking in documentation - https://docs.dfhack.org/en/stable/docs/Lua%20API.html#named-types contains the following, but doesn't go into much more detail:
In addition to this, enum and bitfield types contain a bi-directional mapping between key strings and values, and also map _first_item and _last_item to the min and max values.

If you need to iterate over the enum, you can use ipairs(df.need_type) for that (but there's no need to do that just to build the table you want, since it already exists).
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.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2658 on: October 27, 2020, 12:18:09 pm »

Thanks for sorting that out, lethosor.
Logged

andrian

  • Bay Watcher
  • If all else fails, hit it with a hammer.
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2659 on: October 28, 2020, 05:58:26 pm »

So, I know nothing about LUA scripting, and I know that what I want should be relatively simple, so I'm hoping someone can help me out here. I want a script that will run periodically and just do some basic maintenance to my fort. Everything I want to do is stuff I can do in DFHack with basic scripts, but which I'd rather not type out regularly. Simple things like making the dwarves happy (since that's basically impossible to do any other way right now), removing the frayed socks nobody is wearing, destroying any seeds that might be stuck in cages, and whatever other things I might want done regularly - say every season or so. I know there are scripts that do similar things, but I don't really know how to read them, and as I can't imagine wanting to do anything more complicated than this right now, I thought I'd ask if someone could help me out by writing up a script that will run automatically when the season changes and telling me how to call DFHack scripts and commands using lua, and where to put them within the script.

myk

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2660 on: October 28, 2020, 07:19:53 pm »

If you know the individual commands that you need to run, you can just write them to a text file and then auto-run those commands with the repeat script.

For example, say you want to run the 'cleanowned' script and save your game once a month. You could write a text file named maintenance.txt in your DF directory with the following contents:

Code: [Select]
cleanowned X
quicksave

then put this in your onMapLoad.init file:

Code: [Select]
repeat -name maintenance -time 1 -timeUnits months -command [ script maintenance.txt ]
I haven't tested the above, so if anyone spots any errors in those instructions, please chime in. But this general technique should be able to get you what you want.
« Last Edit: October 28, 2020, 07:26:18 pm by myk »
Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2661 on: October 28, 2020, 07:45:17 pm »

You could also use multicmd instead of a separate text file.
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

andrian

  • Bay Watcher
  • If all else fails, hit it with a hammer.
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2662 on: October 29, 2020, 12:58:50 am »

If you know the individual commands that you need to run, you can just write them to a text file and then auto-run those commands with the repeat script.

For example, say you want to run the 'cleanowned' script and save your game once a month. You could write a text file named maintenance.txt in your DF directory with the following contents:

Code: [Select]
cleanowned X
quicksave

then put this in your onMapLoad.init file:

Code: [Select]
repeat -name maintenance -time 1 -timeUnits months -command [ script maintenance.txt ]
I haven't tested the above, so if anyone spots any errors in those instructions, please chime in. But this general technique should be able to get you what you want.

I don't see any file labeled onMapLoad.init. If I create one in the main DF directory, will DFHack run it automatically when the map loads?

myk

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2663 on: October 29, 2020, 01:27:27 am »

That's the idea, yeah :-) more info on init files here
« Last Edit: October 29, 2020, 01:30:29 am by myk »
Logged

A_Curious_Cat

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2664 on: October 29, 2020, 05:03:45 pm »

I still haven't gotten any confirmation email from DFFD.  How long is this supposed to take?
Logged
Really hoping somebody puts this in their signature.

myk

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2665 on: October 29, 2020, 05:35:04 pm »

I don't know, but I'd suggest:

1. Check your spam folder, and if nothing relevant is in there, then
2. Upload the archive to your Google drive and set the share settings to allow public access. You can always delete it later and get the space back
Logged

A_Curious_Cat

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2666 on: October 29, 2020, 06:54:41 pm »

Just found the confirmation in my spam folder.  The link expired yesterday.  Gonna have to register again.

Edit:

Ok, the part in the email about the link expiring in 15 days turned out to not exactly be true.  I've activated the account and I can now log in.

Now to remember what I was going to do back on the 13th...

Ah, yes!  Time to fire up DF for the first time in more than 2 weeks and make some screenshots...

Edit2:

Interesting...  Now I seem to be unable to reproduce the problem I had on the 13th.

Anyways, I've edited the embarks geo biome with biomemanipulator.  Time to embark carefully...

Edit3:

I aborted the game because I rolled a bad starting seven and for some reason when I went back in it appears that all the changes I made with biomemanipulator were lost.  Does anyone know how to make biomemanipulator changes permanent?
« Last Edit: October 29, 2020, 08:43:59 pm by A_Curious_Cat »
Logged
Really hoping somebody puts this in their signature.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2667 on: October 30, 2020, 04:05:08 am »

To make Biome Manipulator changes stick the game has to be saved, and I don't know a way to save while in the embark mode. You can embark somewhere uninteresting, and then abandon, as that ought to lead to a save (I've never actually tried that method, though).

However, you can avoid a repeat to some extent by using Dwarf Therapist to check your starting 7 (it does work during your careful planning phase) and abort the embark effort if you don't like the dorfs. You're then back to the embark screen and can make a new attempt at the same location. Since you haven't exited DF the changes remain (but be careful with Region Manipulation changes: they are lost when focus is changed, so there's a significant risk those changes have to be redone).
Logged

myk

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2668 on: October 30, 2020, 10:58:33 am »

If you restart when you get a bad starting seven, the armoks-blessing script might be useful for you. I've actually written a variant of that script that is slightly less overpowered. instead of setting all skill for all dwarves to 20, it bumps the skills that already have at least a point in them to 5 (in addition to elevating all mental and physical attributes to an ideal). I can submit that variation for inclusion in DFHack if there is interest.
Logged

A_Curious_Cat

  • Bay Watcher
    • View Profile
Re: DFHack 0.47.04-r3
« Reply #2669 on: October 30, 2020, 01:24:30 pm »

However, you can avoid a repeat to some extent by using Dwarf Therapist to check your starting 7 (it does work during your careful planning phase) and abort the embark effort if you don't like the dorfs. You're then back to the embark screen and can make a new attempt at the same location. Since you haven't exited DF the changes remain

That's exactly what I did.  And the changes still got lost, even though I never actually fully exited out of DF.

Btw, the ability to look at the starting seven's stats during the planning carefully stage is one of the best things since sliced bread.
Logged
Really hoping somebody puts this in their signature.
Pages: 1 ... 176 177 [178] 179 180 ... 244