Option 1: Use match
Instead of too much if elif else
we can try using match
.
func executeStep():
match currentStep:
0:
step1()
1:
step2()
2:
step3()
currentStep += 1
If you go with this option then you won't need the steps
array anymore.
Option 2: Use Callables
We can use a Callable to store a function, and then we can call the function any time we want (as many times as we want).
var steps = [Callable(self, "step1"), Callable(self, "step2"), Callable(self, "step3")]
var currentStep = 0
func executeStep():
steps[currentStep].call()
currentStep += 1
If we need to pass in arguments we go steps[currentStep].call(arg1, arg2, arg3)
, where for example I passed in three arguments.