Godot Version
4.2.2
Question
Hey all. Have recently been messing around with Godot and decided to try and create an “Action Queue” using Callables.
However I’ve been a bit stumped with an error I’ve gotten when I try to call “AddTest()” from the struct list.
I’m not very familiar with C# but I think it’s something to do with scope.
Code:
public struct ActionNode{
public Callable Action {set;get;}
public ActionNode(Callable action){
this.Action = action;
}
public void AddParameter(Variant parameter){
Callable temp = this.Action;
this.Action = Callable.From(() => temp.Call(parameter));
}
};
public partial class QueueHandler : Node
{
private List<ActionNode> actionQueue = new List<ActionNode>();
private int testNumber = 0;
public override void _Ready(){
actionQueue.Add(new ActionNode(false, "Add 1", new Callable(this, "AddTest")));
actionQueue[0].AddParameter(1);
}
public void StepQueue(){
actionQueue[0].Action.Call();
actionQueue.RemoveAt(0);
}
private void AddTest(int toAdd){ testNumber += toAdd; }
}
The function works fine when called in _Ready(), but throws the debug error listed below when called from StepQueue(), which is connected to a Button signal.
GD.cs:366 @ void Godot.GD.PushError(string): Invalid call. Nonexistent callable 'Node(QueueHandler.cs)::AddTest'.