Why is randomize not making my number random?

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

Pretty much what the title says I am using randomize() in the ready function and yet my number stays the same in game and when I restart the game.

here is a pasteall link with my code in it,(Dont worry it only has a few lines)

Do you happen to still have the pasteall of that erroneous code? (I assume you deleted it- if not then something’s just wrong with the site at the moment so disregard)
I know you said you fixed it but I’m still having the problem and I’d like to see where you went wrong before you figured it out

seaking | 2021-02-02 06:00

simply put randomize() in the ready function

like so:

extends Spatial

func _ready():

func _on_Area_body_entered(body):
var number = randi() % 100 + 1
if body is Player:
if number < 30:
print("The number is less then 30 and is " + str(number))

Dragon20C | 2021-02-02 07:17

:bust_in_silhouette: Reply From: Dragon20C

Okay I figured it out, it seems the number var needs to be in a function so it actually gets updated and is random, well Im leaving it up for others who make a noob mistake like me.

You said you are leaving it, so do you know a way to delete a question here?

devAS | 2021-01-11 12:02

You can click the “hide” button next to the edit button.

exuin | 2021-01-11 17:33