Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Godot_Starter |
If you make this:
func _ready():
var x = 1/10
print(x)
It prints 0, but it must be 0.1
Why and how can I fix that?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Godot_Starter |
If you make this:
func _ready():
var x = 1/10
print(x)
It prints 0, but it must be 0.1
Why and how can I fix that?
Reply From: | Schweini |
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: Static typing in GDScript — Godot Engine (stable) documentation in English
Reply From: | klaas |
HI,
because 1 and 10 are integer and not floating point.
Try 1.0 / 10.0 this should do the trick.