Skip to content

Conversation

@Goober5000
Copy link
Contributor

Storage of persistent variables had been broken since #1631 -- the player-persistent variable code would inadvertently not run if there were no campaign-persistent variables. Additionally, there were several places where the persistent variable logic was hard to follow, which could have hidden other related bugs. This fixes the check and cleans up and consolidates the relevant functions.

@Goober5000 Goober5000 added this to the Release 25.0 milestone Jan 18, 2026
@Goober5000 Goober5000 added cleanup A modification or rewrite of code to make it more understandable or easier to maintain. fix A fix for bugs, not-a-bugs, and/or regressions. labels Jan 18, 2026
@Goober5000 Goober5000 force-pushed the variable_fix branch 4 times, most recently from 0f0de2a to ef67aec Compare January 19, 2026 01:43
Storage of persistent variables had been broken since scp-fs2open#1631 -- the player-persistent variable code would inadvertently not run if there were no campaign-persistent variables.  Additionally, there were several places where the persistent variable logic was hard to follow, which could have hidden other related bugs.  This fixes the check and cleans up and consolidates the relevant functions.
@Goober5000 Goober5000 marked this pull request as ready for review January 19, 2026 21:37
Copy link
Member

@jg18 jg18 left a comment

Choose a reason for hiding this comment

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

Still reading, but adding a few thoughts.

}
if (store_red_alert) {
for (auto& current_rav : Campaign.red_alert_variables) {
Campaign.persistent_variables.push_back(current_rav);
Copy link
Member

Choose a reason for hiding this comment

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

We should probably check for naming collisions between existing persistent variables and the RA variables we're adding. Ditto for containers.

} else if (any(persistence_type & ContainerType::SAVE_ON_MISSION_PROGRESS) &&
any(container.type & persistence_type) && container.is_eternal()) {
// we might need to save some eternal player-persistent containers
if (!any(container.type & persistence_type)) {
Copy link
Member

Choose a reason for hiding this comment

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

Use none() instead of !any().

Copy link
Member

@jg18 jg18 left a comment

Choose a reason for hiding this comment

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

Still studying, but one concern.

int num_mission_variables = sexp_campaign_file_variable_count();
int num_sexp_variables = sexp_variable_count();
for (int i = 0; i < num_sexp_variables; i++) {
if (!(Sexp_variables[i].type & persistence_type)) {
Copy link
Member

Choose a reason for hiding this comment

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

The code assumes all "set" variables are packed to the left in Sexp_variables. Can we be 110% sure that will always be true?

I suggest

for (int i = 0; i < MAX_SEXP_VARIABLES; i++) {
	if (!(Sexp_variables[i].type & (SEXP_VARIABLE_SET | persistence_type))) {
		continue;
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup A modification or rewrite of code to make it more understandable or easier to maintain. fix A fix for bugs, not-a-bugs, and/or regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants