fix: set a proper guard in case of no speaking animations (#488)

+ correct the upper limit check for the speaking index
Co-authored-by: Duncan Brown <duncan@bhs-consultants.com>
This commit is contained in:
Duncan BrownandDuncan Brown authored and GitHub committed 2022-02-06 11:24:55 +01:00
1 parent 6f346a9074
commit 326618df18
1 file changed
+9 -6
@@ -452,9 +452,11 @@ func turn_to(object: Node, wait: float = 0.0):
# Play the talking animation # Play the talking animation
func start_talking(): func start_talking():
if get_animation_player() and \ # Only start the speaking animation if we actually have them setup
_movable.last_dir >= 0 and \ if animations.speaks.size() > 0 \
_movable.last_dir <= animations.speaks.size(): and get_animation_player() \
and _movable.last_dir >= 0 \
and _movable.last_dir < animations.speaks.size():
if get_animation_player().is_playing(): if get_animation_player().is_playing():
get_animation_player().stop() get_animation_player().stop()
get_animation_player().play( get_animation_player().play(
@@ -464,9 +466,10 @@ func start_talking():
# Stop playing the talking animation # Stop playing the talking animation
func stop_talking(): func stop_talking():
if get_animation_player() and \ if animations.speaks.size() > 0 \
_movable.last_dir >= 0 and \ and get_animation_player() \
_movable.last_dir <= animations.idles.size(): and _movable.last_dir >= 0 \
and _movable.last_dir < animations.speaks.size():
if get_animation_player().is_playing(): if get_animation_player().is_playing():
get_animation_player().stop() get_animation_player().stop()
get_animation_player().play( get_animation_player().play(