GDScript: division by zero in operator '/'

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Witcher64

I am getting that error on this line:
$MoveTween.interpolate_property(self, “position”, position,
position + moves[facing] * tile_size,
1 / speed, Tween.TRANS_SINE, Tween.EASE_IN_OUT)
my speed is set to three and when i erase my division sign my player moves too fast to see. i do not understand why this is happening or what I need to do to fix it. Thanks for the help, I am a total noob.

extends Area2D

export (int) var speed

var tile_size = 64
var can_move = true
var facing = ‘right’
var moves = {‘right’: Vector2(1, 0),
‘left’: Vector2(-1, 0),
‘up’: Vector2(0, -1),
‘down’: Vector2(0, 1)}

onready var raycasts = {‘right’: $RayCastRight,
‘left’: $RayCastLeft,
‘up’: $RayCastUp,
‘down’: $RayCastDown}

func move(dir): #pg 130 this one is complicated
$AnimationPlayer.playback_speed = speed
facing = dir
if raycasts[facing].is_colliding(): #bracket not parenthisis
return
can_move = false
$AnimationPlayer.play(facing)
$MoveTween.interpolate_property(self, “position”, position,
position + moves[facing] * tile_size,
1 / speed, Tween.TRANS_SINE, Tween.EASE_IN_OUT)
$MoveTween.start()
return true

func _on_MoveTween_tween_completed(object, key):
can_move = true

I just seen jgodfrey’s comment on how to properly post code.

Witcher64 | 2020-09-23 14:33

:bust_in_silhouette: Reply From: klaas

Hi,
you dont provide the exact error … but what i see is you divide two intergers

so 1 / 3 will be zero. Maybe the Tween does not like a duration of zero.

Try “1.0 / speed” this will give you a float result of 0.333333