system
1
|
|
|
 |
Attention |
Topic was automatically imported from the old Question2Answer platform. |
 |
Asked By |
RubRub |
By that I mean what example is this code
func _on_Money_btn_pressed():
GlobalMoney.Money += rand_range(325, 785)
what I want to do is give an exact number if decimals that I give you (example)
450 or 750 coins, no 400.255 or 545.345
system
2
|
|
|
 |
Reply From: |
DaddyMonster |
You need the object which handles it:
var rng = RandomNumberGenerator.new()
func _on_Money_btn_pressed():
GlobalMoney.Money += rng.randi_range(325, 785)
randi_range()
is for integers, randf_range
for floats. Docs: RandomNumberGenerator — Godot Engine (stable) documentation in English
Oh yes it worked for me thank you very much
RubRub | 2021-11-08 17:39
but there is no way to put some specification, by that I mean that I want to give you a number that ends in 5, example 645, 765 or 575
RubRub | 2021-11-08 17:46
Yup, with stepify()
which, as well as having a cool name, does what you need:
var rng = RandomNumberGenerator.new()
func _on_Money_btn_pressed():
GlobalMoney.Money += stepify(rng.randi_range(325, 785), 5)
Docs: @GDScript — Godot Engine (stable) documentation in English
DaddyMonster | 2021-11-08 19:28
Oh thank you very much
RubRub | 2021-11-08 20:58