Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: modtools/create-unit changes.  (Read 1388 times)

Oafsalot

  • Bay Watcher
    • View Profile
modtools/create-unit changes.
« on: May 02, 2020, 02:06:09 pm »

I used this a few versions ago and it was fine. It would spawn a new Dwarf at the cursor.

Code: [Select]
modtools/create-unit -name MOUNTAIN -nick CLONE -race DWARF -caste MALE -civId \\LOCAL -groupId \\LOCAL
Now for some reason, you must specify a location for the dwarf. Which is odd because this makes every example on the internet invalid. But OK.

Code: [Select]
modtools/create-unit -name MOUNTAIN -nick CLONE -race DWARF -caste MALE -setUnitToFort -location [ 132 133 165 ]
The coordinates appear to be from 0 0 1 which is the top left corner in the circus. Not the height/depth bar on the right. Just to add to the confusion.

It would be nice to see this command restored to its old behaviour, so if you don't state a location it defaults to the in-game cursor.

Does anyone know of a good way to get the coordinates of the cursor in dfhack? Would be handy.
« Last Edit: May 02, 2020, 02:13:04 pm by Oafsalot »
Logged
If you like this game why not head over to https://www.patreon.com/bay12games/posts and make a small contribution?!

lethosor

  • Bay Watcher
    • View Profile
Re: modtools/create-unit changes.
« Reply #1 on: May 02, 2020, 04:01:58 pm »

My understanding from https://github.com/DFHack/scripts/pull/99#discussion_r322119747 is that the cursor working was unintentional, and would lead to undesired side-effects if the cursor wasn't active (and so the behavior was changed in 0.44.12-r3).

I would honestly suggest spawnunit as a more concise front-end, and it does specifically default to the cursor position. modtools scripts are generally intended to be used in mods (where a cursor typically wouldn't be active) and may be a little low-level (although create-unit is obviously useful in other cases).

The coordinate system you described is the standard internal coordinate system used by pretty much everything in DF, except for the relative height you see on the map. There are lots of ways to read from it - for example:
Code: [Select]
:lua printall(df.global.cursor)
A shorter way:
Code: [Select]
lua ~cursor

By the way, it's completely fine to post things like this in the main DFHack thread (but thanks for calling our attention to it from there - we don't always notice posts in the larger forum).
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.

Oafsalot

  • Bay Watcher
    • View Profile
Re: modtools/create-unit changes.
« Reply #2 on: May 03, 2020, 12:39:57 pm »

Thanks, lethosor.

You've been a great help.

It took me a while to work out that the [] brackets were not optional. Maybe an example should be put in the documentation?
Logged
If you like this game why not head over to https://www.patreon.com/bay12games/posts and make a small contribution?!

lethosor

  • Bay Watcher
    • View Profile
Re: modtools/create-unit changes.
« Reply #3 on: May 03, 2020, 01:14:14 pm »

It took me a while to work out that the [] brackets were not optional. Maybe an example should be put in the documentation?
It's an argument parsing technique that a lot of scripts use, so having examples of everything for every script could be a lot of work to maintain on our end. I might try to document how it works in a more centralized place, though.
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.

Atomic Chicken

  • Bay Watcher
    • View Profile
Re: modtools/create-unit changes.
« Reply #4 on: May 03, 2020, 02:32:03 pm »

The documentation does quite pointedly include square brackets in its description of the location option (-location [ x y z ]). Is this unclear? Authors sometimes document things in a manner that seems obvious to them without considering how users unfamiliar with system might interpret it, so improvement suggestions are appreciated.

In general, if you see square brackets in the documentation, they should be included where indicated, making sure to leave a space between them and the contained text. In the case of -location, many modtools scripts allow you to specify -location [ \\LOCATION ] in the -command option to pass relevant coordinates to another script, such as modtools/create-unit. For example, modtools/reaction-trigger allows one to do this if they want to create a creature at the location of the workshop following a specific reaction. It would probably be beneficial to document some examples of this.
« Last Edit: May 03, 2020, 02:36:21 pm by Atomic Chicken »
Logged
As mentioned in the previous turn, the most exciting field of battle this year will be in the Arstotzkan capitol, with plenty of close-quarter fighting and siege warfare.  Arstotzka, accordingly, spent their design phase developing a high-altitude tactical bomber. 

bloop_bleep

  • Bay Watcher
    • View Profile
Re: modtools/create-unit changes.
« Reply #5 on: May 03, 2020, 03:52:04 pm »

Usually [] means optional arguments, like in man page synopses, and lots of other documentation places. That might have caused the confusion.
Logged
Quote from: KittyTac
The closest thing Bay12 has to a flamewar is an argument over philosophy that slowly transitioned to an argument about quantum mechanics.
Quote from: thefriendlyhacker
The trick is to only make predictions semi-seriously.  That way, I don't have a 98% failure rate. I have a 98% sarcasm rate.