Why not use Switch statement?

I know this is a bit more advanced C#, but switch statements are the perfect tool to capture the behavior of several if-statements. And I feel this is the perfect opportunity to dive into it. I already used this in the textbased adventure where this structure proved very convenient.

In my code:

switch (action) {
case ActionMaster.Action.Tidy:
	anim.SetTrigger ("tidyTrigger");
case ActionMaster.Action.EndTurn: 
	anim.SetTrigger ("resetTrigger");

Coudn’t agree more

I prefer switches to long series of if-elseif.

1 Like

I was facing a problem with the series of IF statements. actionMaster.Bowl() was being called several times and the bowl count was all messed up.

Thanks for the idea. It solved the problem.

Agree as well!

For clarity I used switch statements and Enums in ScoreMaster as well. Without using these tools I felt that the code was hard to read and would not be easy to go back to.

As see that too, I’ve made a switch statement as I would have done in my JS scripts.

Privacy & Terms