Skip to content

Conversation

SilasD
Copy link
Contributor

@SilasD SilasD commented Jul 23, 2025

Test the current viewscreen to ensure that it is the choose_start_site viewscreen, before trying to use it.

The bug: if the embark-anyone script is executed on any viewscreen other than the embark viewscreen, it aborts with a stack trace.

This bugfix makes it cleanly abort with a reasonably-descriptive error message.

This was found while diagnosing Issue #5509, but is not related.

Minimal changes to the script.

the choose_start_site viewscreen, before trying to use it.

This was found while diagnosing Issue #5509, but is not related.

Minimal changes to the script.
Copy link
Member

@ab9rf ab9rf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might want to consider adding a utility function for asserting a specific viewscreen as I see that similar code is found in unretire-anyone and equality checks are found in four other scripts, but that's not required for this PR

@@ -3,6 +3,9 @@ local utils = require('utils')

function addCivToEmbarkList(info)
local viewscreen = dfhack.gui.getDFViewscreen(true)
if viewscreen._type ~= df.viewscreen_choose_start_sitest 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 code is duplicated, which means it should be pulled out as its own function that is called in both places that it appears

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intent was to keep the changes minimal. I'm willing to refactor if you think it's important.

Copy link
Member

@ab9rf ab9rf Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a strong objection to duplication of code and any sort of cut-and-paste programming. Toady does this a lot and DF's code suffers for it.

Also, a change that doesn't duplicate code would not be less minimal than the change you're proposing, at least by my standards.

Copy link
Contributor Author

@SilasD SilasD Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, found a minimal-change that doesn't duplicate code.

Edit: what is the local policy on comments? I was shocked to see how few comments there are in most scripts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a lot of solid editorial policy in general, and I'm especially poorly suited to comment as I am not much of a Lua programmer and thus don't have a sense of what good form for Lua would be

The bug: if the embark-anyone script is executed on any viewscreen other than the embark
viewscreen, it aborts with a stack trace.

This bugfix makes it cleanly abort with a reasonably-descriptive error message.

This was found while diagnosing Issue #5509, but is not related.

Minimal changes to the script.

Note on the code change: by moving the function addCivToEmbarkList() inside the function
embarkAnyone(), addCivToEmbarkList() cannot execute unless embarkAnyone() has at least
passed its safety check.
@SilasD SilasD requested a review from ab9rf July 24, 2025 14:53
@ab9rf ab9rf merged commit 1c6ef8e into DFHack:master Jul 24, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants