Barotrauma

BUG OF THE MONTH | Unnecessary actions

V3107 Identical expression ‘power’ to the left and to the right of compound assignment. RelayComponent.cs 150

public override void ReceivePowerProbeSignal(Connection connection, 
                                             Item source, float power)
{
  ....
  if (power < 0.0f)
  {
    ....
  }
  else
  {
    if (connection.IsOutput || powerOut == null) { return; }

    if (currPowerConsumption - power < -MaxPower)
    {
      power += MaxPower + (currPowerConsumption - power);
    }
  }
}

The programmer is trying to add MaxPowerpower and the difference between currPowerConsumption and power. The expanded version of the expression will look as follows:

power = power + MaxPower + (currPowerConsumption - power);

There’s no need to subtract the power variable from itself. The simplified code will look like this:

power = MaxPower + currPowerConsumption;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.