0 votes

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
Godot version 3.1
in Engine by (48 points)

Does size_detection run once?

yes I run it in physic_ process ()

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.

i put it in another place and it works thanks

1 Answer

0 votes

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

by (4,972 points)

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

here is a screenshot: https://zupimages.net/viewer.php?id=21/13/j49m.jpg

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

Naturally _physic_process moves really fast and you are reassigning your value

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.