Static typing not working for floats?

Godot 4.0

I was experimenting with variables of which types were static. I found that for some reason I could still change the type. For example, if the static variable was an integer, i could change it to a float and not receive an error and the code would work fine. However, if the static variable was an integer and I changed it to a string, the code would give me an error and would not work. Why is this?

CHANGING STATIC VARIBALE TO FLOAT:

extends Node


var test := 15

func _ready():
	test = 15.5
	print(test)

OUTPUT:

CHANGING STATIC VARIABLE TO STRING:

extends Node


var test := 15

func _ready():
	test = "hi"
	print(test)

OUTPUT:
Parse Error: Cannot assign a value of type “String” as “int”.

What you are claiming is not true. And in your provided example you dont change the type. 15 and -239 are both integers

2 Likes

oh i guess i must’ve confused myself thinking that you can’t change the value of a static variable. I see now that it just means the type stays the same but you can still change the value. Here i did another test to try to change the type but the output returns an integer because booleans are binary and true = “1” i think. You’re right, thanks.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.