Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

doublestrafe2096
Copy link

New lua script: ezprefs.lua tool for changing citizen preferences. Lots of documentation in the lua file.

New lua script: ezprefs.lua tool for changing citizen preferences.
local argparse = require("argparse")
local opts = {}

local help = [====[
Copy link
Member

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 = [====[
Copy link
Member

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 = [====[
Copy link
Member

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
Comment on lines 400 to 401
creatures['everyone'] = {'BIRD_TURKEY','FLY','FLY_ACORN','SHEEP'}
creatures['noble'] = {'DOG','CAT','PIG','BIRD_TURKEY','FLY','FLY_ACORN','SHEEP','CRUNDLE','CROCODILE_CAVE'}
Copy link
Member

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

Comment on lines +506 to +510
local function print_yellow(text) --Lifted directly from assign-preferences.lua
dfhack.color(COLOR_YELLOW)
print(text)
dfhack.color(-1)
end
Copy link
Member

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()
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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

Comment on lines +905 to +912
if positionals ~= nil and #positionals > 0 then
print(shorthelp)
return
end

if opts.help then
print(help)
return
Copy link
Member

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())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants