I followed an old tutorial about a card game and, after finishing it, I started removing some code I didn't like or it was simply not compatible with Godot 4.
Anything went fine, except for one thing.
In the game are declared two unneeded one-shot timers: they do the exact same thing, with the same delay but, once fired, they must call two different functions.
I refactored the code to have only one timer.
One solution worked, but I wanted to know why the other one didn't.
In the _ready
function there's a function setupTimers, where I have:
c = Callable(self, method)
flipTimer.connect("timeout", c)
method
is a global containing the -variable- string name of a function:
I change its value just before calling flipTimer.start(1)
, but problem is, once declared the Callable
, method
takes its current value and it cannot change anymore (I even tried using a function to return
the current method value).
Is there any way to make it work the way I hoped?
The solution that worked is a little bit different:
- I provide the name of a function directly;
- the function is called on timeout;
- inside the body of the function I
expression.execute
the function names;
This way it works, but why the other don't? I suppose Callable stores a value that can't be variable but I'd like to know if there's a way to get around this limitation.