Storing functions in a list/array?

Hello!

I am desperatly looking for help! I’m working on RTS game and I want to make an list/array of functions, which the unit would go through in the order and execute the functions one by one. I’ve been googling and trying to figure this out for almost week now.

Currently I have this:

var unitQueue : List.<Function> = new List.<Function>();
public function Move(location) {
//Move to location
}

and I’m trying to add this function in array with:

unitQueue.Add(Move(location));

This returns me an error:

 BCE0017: The best overload for the method 'System.Collections.Generic.List.<Function>.Add(Function)' is not compatible with the argument list '(void)'.

Any ideas, fixes?

That’s the incorrect syntax to create a dynamic function in javascript. What you do is actually call Move(location), and put the result inside the queue.

If you want to put the function call itself, you need to create a dynamic function:

Javascript:

unitQueue.Add(function () { Move(location); });

C#:

List<System.Action> unitQueue = new List<System.Action>();
unitQueue.Add(() => Move(location));

Here’s some reading material about lambda expressions in Javascript: Javascript Jems - Lambda expressions