0 votes

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)

https://pasteall.org/DVg4

Godot version 3.2.3
in Engine by (156 points)

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

simply put randomize() in the ready function

like so:

extends Spatial

func _ready():
randomize()

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

1 Answer

0 votes

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.

by (156 points)

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

You can click the "hide" button next to the edit button.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.