0 votes

If you make this:

func _ready():
    var x = 1/10

It prints 0, but it must be 0.1

Why and how can I fix that?

in Engine by (378 points)

2 Answers

+2 votes
Best answer

because 1 and 10 are integer and not floating point.
Try 1.0 / 10.0 this should do the trick.

by (4,088 points)
selected by
0 votes

As GDScript is a dynamic language, I assume Godot assigned x as an integer.

If you want x to be 0.1 you have to write var x : float = 1/10, this is static typing.

For more information: https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/static_typing.html

by (232 points)
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 Frequently asked questions and 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 [email protected] with your username.