hi guys… Sorry to bother but I really need to know how to cut Decimals from var pluses = 0.
Sorry prolly it’s easy but in these days I’m really studying and doing my exams so I’m a lil stupid.
I saw posts but I couldn’t find anything. Btw the system is that you can send “money” to the other people and for changing the money (value) you type in the line edit or you hold/ press the + or - button.
The problem with the + button Is that It goes too fast when held. So I tried multiply by speed. And it worked but the problem is now that I have Decimals. And I don’t need them
*I tried using integer division by 10
The value before was " var pluses = 0 (yes I messed it up)
###Here’s the script:
extends CanvasLayer
var pluses = int(float(0) / 100.0)
var innff = false
var speed = 0.1
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
%sjsjajj.text = str(pluses)
if innff == true:
pluses += 1 * speed
func _on_plu_pressed() -> void:
pass
func _on_minu_pressed() -> void:
pluses -= 1
if pluses < 0:
pluses = 0
func _on_plu_button_down() -> void:
innff = true
func _on_plu_button_up() -> void:
innff = false
It’s still the same but now I tried ceil and it works I just need to remove .0 and it’s fine but I think I’ll leave it like this. Thanks for the help tho!
You don’t use it anywhere in your code so I can’t tell how you use it, but that’s fine if you actually want to round up instead of removing the decimals as was the question
Just using int(var) will fully strip the decimals if you are using negative numbers as well, as it truncates the value
_process is called every frame, so your code ends up constantly performing checks that aren’t necessary. What I gather from the post is that you want certain behavior when the button is pressed or held. To that end, you can use the button_down and button_upsignals.
If you add a timer to your class, you can set its timeout value to something practical like 0.25 seconds. Then have the timer start when the button_down signal fires, and stop when button_up fires. Then edit the variable representing money every time the timer elapses.
If your statically type your variable representing money as an integer, then you will never have decimals unless you do some type casting trickery.
This is just a friendly bit of advice, but, if somebody gives you a solution and it doesn’t work, it’s considered good practice to share in what way the solution doesn’t meet expectations.