GDscript: how to get an int from a node?

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

Objective:


Get an int from the user and output it.

This is nowhere near the original question

Eric Ellingson | 2019-07-14 15:46

Hi, sorry about that, I tried to simplify my ask.
I had some problems in my error checking too.
I got the correct int input once I fixed my conditional operators…
I ended up using stepify to round the float to 2 decimal places.
I got everything working.
Thanks for the feedback.

GodotUser | 2019-07-15 03:25

:bust_in_silhouette: Reply From: Eric Ellingson
randomize()
var value_float = rand_range(0, 10) # random float between 0 and 10
var value_int = randi() % 11 # random in between 0 and 10

to specify a range for the int version you could use a function like:

func rand_int(_min, _max):
	randomize()
	return (randi() % (_max + 1 - _min)) + _min

Thanks, however I am not looking to randomize anything here.

I wish to get input from the user and output it.

I solved the problem and provide the solution.

GodotUser | 2019-07-14 03:27

Not sure what is going on with all the down votes, but anyways… Maybe you could try using the stepify function: @GDScript — Godot Engine (3.1) documentation in English

Eric Ellingson | 2019-07-14 06:46

:bust_in_silhouette: Reply From: GodotUser

Solution:


 func _on_CalcResult_pressed():
	# Get input from node
		QTY = int(get_node("../UI/QTY").text)
		# print output as int
			print(int(QTY))