Using Default Parameters

Another option for the unnecessary parameters is to use default parameters. You’ll still have an unneeded GridPosition in SpinAction.TakeAction but, at least you wouldn’t need to pass anything in the code that calls the Take Action Method.

In SpinAction:

public void TakeActionAction onActionComplete, GridPosition gridPosition = GridPosition.zero)
    {
        
    }

and in the code that calls SpinAction:

spinAction.TakeAction(ClearBusy);
2 Likes

Could you elaborate how to implement GridPosition.zero?

I’ve done it like this:

public static readonly GridPosition zeroPosition = new GridPosition(0, 0);

and this gives me an error:

Default parameter value for must be a compile-time constant

The GridPosition is a struct, so it cannot be null. The easiest zero would then just be

public static readonly GridPosition zero = default;

Privacy & Terms