why when i make 300/4 it say me the result is 0

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

hello i am working on my project i was trying divide my speed variable (which is 300) by 4 its telling me the result and 0 i tried to convert it to float but its not working

here is my variables

export (int) var speed = 300
export (int) var jump_speed = -600
export (int) var gravity = 1500
export (float, 0, 1.0) var friction = 0.25
export (float, 0, 1.0) var acceleration = 0.25
onready var sprite = get_node("icon")
onready var collider = get_node("CollisionPolygon2D")
var velocity = Vector2.ZERO

and here is my function

func size_detection():
	if $icon.scale == Vector2(0.125,0.125):
		speed = float(speed) / 4.0
		gravity = float(gravity) / 4.0
		jump_speed = float(jump_speed) / 4.0

Does size_detection run once?

exuin | 2021-04-03 15:34

yes I run it in physic_ process ()

sphixy011 | 2021-04-04 06:26

But that runs every frame! So your function doesn’t run once. You need to put it in the ready function or somewhere where it only runs once.

exuin | 2021-04-04 12:39

i put it in another place and it works thanks

sphixy011 | 2021-04-04 17:39

:bust_in_silhouette: Reply From: Wakatta

Since your var is an exported ensure the editor displayed one matches the scripted one as the editor one supersedes here.

Unless speed is otherwise referenced or modified your code looks pretty standard and correct

when i print my variable is say me the reult is 0 but in the inspector nothing changes

here is a screenshot: 21/13/j49m.jpg - Visionneuse Zupimages

sphixy011 | 2021-04-04 06:29

I understood why it didn’t work I executed my function size detector in my physic _process it detected all the time and divided it all the time up to 0

sphixy011 | 2021-04-04 06:53

Naturally _physic_process moves really fast and you are reassigning your value

Wakatta | 2021-04-04 20:37