-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New lua script: ezprefs.lua tool for changing citizen preferences. #872
base: master
Are you sure you want to change the base?
Conversation
New lua script: ezprefs.lua tool for changing citizen preferences.
local argparse = require("argparse") | ||
local opts = {} | ||
|
||
local help = [====[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs for in-tree scripts should to into dedicated .rst files in the docs
directory. Some markup will need to be added, including the header that defines the summary and tags. Look at other .rst files in the docs directory for examples, or see the full guide here: https://docs.dfhack.org/en/stable/docs/dev/Documentation.html
-s, --silent Suppress non-error messages. | ||
]====] | ||
|
||
local tips = [====[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding the tips as a section to the main help. the help text is automatically displayed in gui/launcher
when someone types the ezprefs
command. there's no need to make them run the command to read what could already be a section in the help text.
moreover, adding it to the canonical help text will allow it to be rendered and displayed in our online docs.
|
||
]====] | ||
|
||
local shorthelp = [====[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I experimented with short help like this for quickfort
. My advice is to not have it. it increases the maintenance burden by adding an additional (and non-standard) location for help text that needs to be kept up to date.
I removed the short help for quickfort
here
ezprefs.lua
Outdated
creatures['everyone'] = {'BIRD_TURKEY','FLY','FLY_ACORN','SHEEP'} | ||
creatures['noble'] = {'DOG','CAT','PIG','BIRD_TURKEY','FLY','FLY_ACORN','SHEEP','CRUNDLE','CROCODILE_CAVE'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and geese! don't forget about geese! they're just as viable as turkeys
local function print_yellow(text) --Lifted directly from assign-preferences.lua | ||
dfhack.color(COLOR_YELLOW) | ||
print(text) | ||
dfhack.color(-1) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this appears to be used for printing errors. try dfhack.printerr()
instead. It's red, not yellow, but it's the standard for things like this.
end | ||
|
||
----------------------- GET_ALL_UNITS ------------------------------- | ||
local function get_all_units() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using dfhack.units.getCitizens(true)
instead
elseif not opts.all then | ||
if not opts.preview then | ||
opts.unit = process_unit() -- looking for a selected unit | ||
unit=opts.unit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit
is a global var in this scope. are you missing a local unit
in this function?
-------------------------- DO_ACTIONS ----------------------------- | ||
local function do_actions(job_list) | ||
if opts.all then | ||
--opts.silent = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented-out code isn't generally useful. can this line be removed?
return | ||
end | ||
----------------------------------------------------------------------- | ||
if not dfhack_flags.module then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this script isn't declared as a module, so this if guard isn't necessary
if positionals ~= nil and #positionals > 0 then | ||
print(shorthelp) | ||
return | ||
end | ||
|
||
if opts.help then | ||
print(help) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once the help text is in the .rst file, you can print the help with print(dfhack.script_help())
New lua script: ezprefs.lua tool for changing citizen preferences. Lots of documentation in the lua file.