[SampleController5.cs] Difficulty Understanding Technical use of method call w/o param

(Joao Rocha) #1

In the following code how can you call a reference to checkIfValidNode with 0 params not even using brackets, when checkIfValidNode has 1 param
of the type MapNavNode?
I cannot follow the code logic.

[screenshots removed: just paste code snippets or specify line numbers when possible. it uses much less server resources than an image]

(Joao Rocha) #2

I have already been told you used a lambda. Is that the case?

I was given the following example to illustrate what you did here, I just need you to confirm if this case illustrates what you did in here or not:

public void Main()

public void DoSomething(Func method)

public void MyMethod(int num)

(Joao Rocha) #3

Ok once again, after some investigation I saw the reason why it is that you don’t have a param, but after all it is not lambdas, you are using a delegate as a type of paramter, where you called the checkIfValid method reference as an argument.

Is that correct?

(Leslie Young) #4

CheckIfValidNode() will be called by the MapNavBase.NodesAround() (or override in MapNavHexa or MapNavSquare depending on which you use) when it needs to know something about a tile.

NodesAround will pass a parameter, the tile it is currently looking at, to CheckIfValidNode when it makes the call.

In MapNavHexa .cs you will see this for example where callback is the CheckIfValidNode method that was passed to
public override List<T> NodesAround<T>(MapNavNode node, bool includeInvalid, bool includeCentralNode, ValidationCallback callback)

if (callback != null)
	if (false == node.isValid || false == callback(node))

CheckIfValidNode should simply return true or false to indicate whether a tile is consifered “valid” for the use case. You can have various CheckIfValidNode methods depending on what you want to know from the method that makes use of it, like the NodesAround() and Path() methods.

In this case I simply wanted to exclude tiles which have units on them but you might have other reasons for a tile to be invalid for pathing, or whatever reason you have for requesting a list of nodes around the current node. You might consider a tile wit hw all but not a unit on it as invalid if it might block a ranged shot for example.