Topic on the same question is already exist, but I created this to give more structured context.
Godot Version
4.2.0
Contecst
I with my team making custom cutscene system. we have class Plot
that contain and execute Command
classes. Command
class is basic class for different actions: Wait
or PlayAnim
foe example.
Plot
executin every Command
in func Run()
.
Right now we making feature, that will execute them in turn, waiting for execution of each. For that purpose we have await (something); return 0
.
So we thought it will work like tis: await
in for
is waiting await
of current executioning class and then executes necst. But forsome reason it didnt work
Plot.gd
class_name Plot
var _commands = []
var _cutscene
func _init(cutscene):
_cutscene = cutscene
func Add(command : Command):
_commands.append(command)
func _Reset(cutscene : Node):
for node in cutscene.get_children():
if node is PhantomCamera2D:
node.set_priority(0)
func Run():
for command : Command in _commands:
await command.Execute(_cutscene)
_Reset(_cutscene)
Command.gd
class_name Command
func Execute(cutscene : Node) -> int:
return 0
PlayAnim.gd
class_name PlayAnim
extends Command
var _name # node name
var _anim # animation name
var _is_async # sets delay for waiting till its done
func _init(name,anim = "default",is_async = false):
_name = name
_anim = anim
_is_async = is_async
func Execute(cutscene) -> int:
for node in cutscene.get_children():
if node is AnimationPlayer:
if node.get_name() == _name:
node.play(_anim)
if(_is_async):
await node.animation_finished
return 0
return 1
Wait.gd
class_name Wait
extends Command
var _time_sec # wait time
func _init(time_sec : int):
_time_sec = time_sec
func Execute(cutscene : Node) -> int:
await cutscene.get_tree().create_timer(_time_sec).timeout
return 0
The problem
for
in Run()
is executing first Command
but then it just ignoring others and game continues to running.
Why for
is skipping others and how to make it work?
Or maybe for
is still waiting for command
to fully execute and rest of the game code is working as normal?