Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 188 189 [190] 191 192 ... 360

Author Topic: DFHack 0.43.03-r1  (Read 1087477 times)

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2835 on: June 22, 2015, 08:41:05 am »

Could anyone kindly explain to me how to insert new values to int32_t vectors in gm-editor?
(For instance, if I wanted to add a value for style_strength of a certain written_content).
It doesn't look like it's possible at the moment, but you can use "vector:insert('#', number)" in the lua interpreter.
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.

expwnent

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2836 on: June 22, 2015, 08:52:16 am »

does the df::global::world.buildings.all vector contain every building ever made, including removed ones?

I'm trying to decide how I will send over constructed buildings to Armok vision. I don't want to send more than I need to, but besides searching through all buildings and picking the ones that are inside a specific map block, I'm not sure how that could be done.

I'm 90% sure that it does not.
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2837 on: June 22, 2015, 09:07:02 am »

I just checked, and no, it only contains actually existing and/or planned buildings.

So now it becomes a question of it it's fine to just send over the entire list, or if I would need to filter it so it only includes the map blocks I'm currently looking at.
Logged

Prismatic

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2838 on: June 22, 2015, 03:03:06 pm »

Could anyone kindly explain to me how to insert new values to int32_t vectors in gm-editor?
(For instance, if I wanted to add a value for style_strength of a certain written_content).
It doesn't look like it's possible at the moment, but you can use "vector:insert('#', number)" in the lua interpreter.

Excuse my ignorance (I have practically no experience using lua), but could you please elaborate on that? Entering "vector:insert('#', 0)" in the lua interpreter on the dfhack console yielded the following error message:
Spoiler (click to show/hide)
I'm most definitely just omitting something obvious. Should the vector be specified? If so, could you explain how?
Thanks for the help!
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2839 on: June 22, 2015, 03:04:31 pm »

"vector" refers to the actual vector you're looking at, yeah. You specify it the same way you navigate to it in gm-editor.

(unit->body.blood_max in gm-editor becomes unit.body.blood_max in lua, for example)

Dirst

  • Bay Watcher
  • [EASILY_DISTRA
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2840 on: June 22, 2015, 04:39:26 pm »

There's definitely a way but I forget what it is. Try looking at the tileprobe plugin. Or maybe it's just called probe? I forget.
The probe command lists three different materials for a tile: layer, base and static.  If and only if the tile is part of a vein, it will also have a vein material.

The layer material doesn't change, and neither does the vein if it's present.  The base and static materials switch from the vein material to the layer material when a tile is mined.  So in pseudo-code:

if layer_stone is spawnable then
    if vein is null OR vein is spawnable then
        spawn-creature-script //layer_stone //location //miner
    end
end


First, will Lua properly short-circuit an OR if the first condition is true?  If I have to capture errors then I'll just find an uglier way to order the tests.

Second, is there a quick way to check if a material matches one of 24 arbitrary materials?  Since this will be an eventful call-back, I'll have a chance to pre-populate a persistent list with numeric ids if that will make a difference in performance.
Logged
Just got back, updating:
(0.42 & 0.43) The Earth Strikes Back! v2.15 - Pay attention...  It's a mine!  It's-a not yours!
(0.42 & 0.43) Appearance Tweaks v1.03 - Tease those hippies about their pointy ears.
(0.42 & 0.43) Accessibility Utility v1.04 - Console tools to navigate the map

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2841 on: June 22, 2015, 04:47:06 pm »

It will properly end a conditional if a pre-OR is true or if a pre-AND is false, yeah. I personally use the idiom "if unit.status.current_soul and (something else)" for checking if a unit has a soul (undead do not) a lot.

kane_t

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2842 on: June 23, 2015, 09:54:02 am »

Does anybody know if there's a way to make dfhack.items.remove() in the Lua API work properly for items in containers?

I'm trying to remove items from the game entirely (as part of a script to merge stacks) and calls to dfhack.items.remove() don't seem to do anything to items stored in a container.  Same deal with items.moveToGround().  If items.remove() won't work, is there any way to get an item out of a container so it can be removed?

Alternatively, does anybody know if the equivalent C++ function on the plugin side works?
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2843 on: June 23, 2015, 10:06:43 am »

It looks like you'd have to remove them from their containers somehow (the same applies to items in workshops and projectiles, among other things). Most of those Lua functions are direct wrappers around the corresponding C++ functions, so there shouldn't be any difference between them.
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.

kane_t

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2844 on: June 23, 2015, 10:31:39 am »

It looks like you'd have to remove them from their containers somehow (the same applies to items in workshops and projectiles, among other things). Most of those Lua functions are direct wrappers around the corresponding C++ functions, so there shouldn't be any difference between them.

Yeah, it appears that, if I remove the general_ref from the container's general_refs vector (by erasing it by index), that removes it from the container.  What worries me is that, even after then calling dfhack.items.remove() on the item, quitting the Lua interpreter, and unpausing the game for a little while, I can still reopen the interpreter and find the item by its id through df.item.find().  That makes me think that it isn't actually being completely removed, and is going to end up causing a memory leak.

The other thing I'm wondering about is how the game will handle it if that item is tasked.  Will dfhack correctly cancel all jobs using the item when calling dfhack.items.remove()?  Or am I going to wind up with a null reference error later on?
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2845 on: June 23, 2015, 11:59:47 am »

What's the return value of remove()? The item should have a corresponding general_ref, and not removing both could cause issues. I think there's also a specific_ref or general_ref for tasked items, which remove() should refuse to touch.
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.

Prismatic

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2846 on: June 23, 2015, 01:53:51 pm »

"vector" refers to the actual vector you're looking at, yeah. You specify it the same way you navigate to it in gm-editor.

(unit->body.blood_max in gm-editor becomes unit.body.blood_max in lua, for example)
Thank you Putnam, that was precisely what I needed to know!
Logged

Dirst

  • Bay Watcher
  • [EASILY_DISTRA
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2847 on: June 23, 2015, 01:57:53 pm »

Second, is there a quick way to check if a material matches one of 24 arbitrary materials?  Since this will be an eventful call-back, I'll have a chance to pre-populate a persistent list with numeric ids if that will make a difference in performance.
Does anyone have a lead on this, either from a Lua angle or a regular expression angle?  Otherwise it turns into looping string match tests, which I imagine would be relatively slow.  There are 49 tests in a worst case scenario, so it might not be too bad.  Would still like a more elegant solution, though.
Logged
Just got back, updating:
(0.42 & 0.43) The Earth Strikes Back! v2.15 - Pay attention...  It's a mine!  It's-a not yours!
(0.42 & 0.43) Appearance Tweaks v1.03 - Tease those hippies about their pointy ears.
(0.42 & 0.43) Accessibility Utility v1.04 - Console tools to navigate the map

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2848 on: June 23, 2015, 02:04:16 pm »

Second, is there a quick way to check if a material matches one of 24 arbitrary materials?  Since this will be an eventful call-back, I'll have a chance to pre-populate a persistent list with numeric ids if that will make a difference in performance.
Does anyone have a lead on this, either from a Lua angle or a regular expression angle?  Otherwise it turns into looping string match tests, which I imagine would be relatively slow.  There are 49 tests in a worst case scenario, so it might not be too bad.  Would still like a more elegant solution, though.

Make a persistent table with the id of each of the materials. Then just use
Code: [Select]
if persistTable.GlobalTable.DirstMatTable[mat.id] then something like that should work
Logged

kane_t

  • Bay Watcher
    • View Profile
Re: DFHack 0.40.24-r3
« Reply #2849 on: June 23, 2015, 03:18:58 pm »

What's the return value of remove()? The item should have a corresponding general_ref, and not removing both could cause issues. I think there's also a specific_ref or general_ref for tasked items, which remove() should refuse to touch.

Good call, I checked the return value (the fact that it returns a value wasn't documented in the Lua API, so I didn't bother to check before) and it was returning false.  A bit of experimentation and looking through the source on github revealed that it wasn't able to remove the item because it was held by a Viewscreen, because I was keeping the barrel inventory open.  If the function is called after closing the barrel's inventory, the item is removed successfully.

It's the items::detachItem() function which checks to see if an item is visible in a viewscreen, by the way, which is also called for lots of similar functions, like putOnGround() and moveToContainer().  Quite inconvenient.

So now my problem is figuring out a way to either remove things while viewscreens are open (which I guess would require manually detaching the item from the viewscreen, which could only be done in a plugin, and might cause other problems I can't predict) or delaying removal until the inventory is closed (which would require continuous polling, and might still require doing it in a plugin to be able to detect whether an inventory window is open).  Or changing my script to only work on containers, instead of the specific items within them, so the user doesn't need to manually select the item.

Alternatively, I might just be able to fool items::remove() by manually removing the in_inventory flag and adding the removed flag after removing the item from the container.

Incidentally, item::remove() also fails if the item is tasked in any way (by having any specific_ref), so that answers that question.
« Last Edit: June 23, 2015, 03:22:15 pm by kane_t »
Logged
Pages: 1 ... 188 189 [190] 191 192 ... 360