r/programminghorror • • Mar 05 '26

C# Found this in my game's code

Post image
288 Upvotes

44 comments sorted by

View all comments

Show parent comment

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Mar 10 '26

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.

1

u/simulacrumgames Mar 10 '26

Which is exactly saying "if the score is different update it"

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Mar 10 '26

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.

1

u/simulacrumgames Mar 10 '26

Ah, I see. That really makes no sense to me as what this is for lol. We can go full insaneo mode then:

inverter = -1 + 2 * (CurrentGameMode == ScoreBased);

for each (team in teams)
{
  lesser = teamScores[team] - CurrentGameMode.Scores[team];
  if (lesser * inverter < 0)
  {
    teamScores[team] = CurrentGameMode.Scores[team];
  }
}

UpdateAndEmitScore();