I'm trying to think of a way to rewrite that in a way that makes the conditional less complicated that doesn't make you put teamScores[team] = CurrentGameMode.TeamScores[team]; twice, and I'm drawing a blank. I'm not willing to transcribe the image and play with it, but I totally would if I could select text and copy and paste it.
private void SyncScoresFromGameMode() {
foreach (Player.Team team in CurrentGameMode.TeamScores.Keys) {
if (CurrentGameMode.ModeCondition == GameModeBase.PrimaryModeCondition.ScoreBased && teamScores[team] < CurrentGameMode.TeamScores[team]) {
teamScores[team] = CurrentGameMode.TeamScores[team];
} else if (teamScores[team] > CurrentGameMode.TeamScores[team]) {
teamScores[team] = CurrentGameMode.TeamScores[team];
}
}
UpdateAndEmitScore();
}
?
Actually, maybe. That if expression gets pretty big that way. Also, unless my brain is failing, I think you have the min and max reversed. Either way, there are two places that need updating if the assignment to teamScores[team] changes.
Min and max really are better because they express the intent directly
teamScores[team] = CurrentGameMode.TeamScores[team]; happening twice is a coincidence, not repetition
This is some kind of cleanup for incorrect calculation of game score that should have happened right away during the game. It's entirely possible that one of these will later include something like team.kickOnePlayer(), and the other wont. Because those are two separate game modes, they can have totally different rules
if (CurrentGameMode.ModeCondition != GameModeBase.PrimaryModeCondition.ScoreBased)
return;
changed = false;
for each (team in teams)
{
if (teamScores[team] != CurrentGameMode.TeamScores[team])
{
changed = true;
CurrentGameMode.TeamScores[team] = teamScores[team];
}
}
if (changed)
UpdateAndEmitScore();
The only real reason to do the check would be to prevent emitting the score unnecessarily. If the stuff that happens on the other side of the emit isn't worth preventing, you shouldn't even check if they're different, just update all the scores and emit every time.
In one case the score is updated if it is less than CurrentGameMode.TeamScores[team], in the other it is updated if it is greater. This seems to have very different behavior.
Yeah, but unless I'm misreading the ternary or something, the logic in the OP is if the game mode is score based, only update the score if it is less than, and if it is not score based, then only update the score if it is greater than. Your code always returns early if the mode is not score based, and if it is, it always updates the score if it differs. I mean, for all I know, your version is how it should work, but this would be why I didn't see how != helps.
View all comments
6
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Mar 05 '26
I'm trying to think of a way to rewrite that in a way that makes the conditional less complicated that doesn't make you put
teamScores[team] = CurrentGameMode.TeamScores[team];twice, and I'm drawing a blank. I'm not willing to transcribe the image and play with it, but I totally would if I could select text and copy and paste it.For sure, this needs several more line breaks.