Is it programmatically necessary to be so wordy?

Is it necessary to have two different variables for the same use?

First, why can’t you call the starting wave the current wave because that’s what is current.

For example, this is the code:

int startingWave = 0;

void Start()
{
    WaveConfig currentWave = waveConfigs[startingWave];
    StartCoroutine(SpawnAllEnemiesInWave(currentWave));
}

Why not have it this way:

int currentWave = 0;

void Start()
{
    StartCoroutine(SpawnAllEnemiesInWave(waveConfigs[currentWave]));
}

or even this way:

int startingWave = 0;

void Start()
{
    StartCoroutine(SpawnAllEnemiesInWave(waveConfigs[startingWave]));
}

The point being is to have one WebConfig and one line in Start(). I am confused as to why.

Hi Terry,

Thank you for your questions.

In Start(), we start spawning our starting wave, which is a predefined wave (index). That is the idea the name startingWave is supposed to convey. Rick used two variables to make the code more readable in his opinion. It’s a matter of personal preference. Longer lines of code are usually harder to read than shorter ones.

In many cases, there are multiple ways to make something work in Unity, and he cannot show all of them.

You seem to have grasped the idea, and you seem to be able to express your idea in code. For this reason, I would say: Use your preferred version. That’s fine. :slight_smile:


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms