0 votes

How can you make something random? Like a every time you press a button, a label shows a number in between 1 and 100. am i clear?

in Engine by (54 points)

1 Answer

+2 votes
by (25 points)

thanks, but i am kinda a noob. i have no idea what there talking about.

Hmmm i think you should do this tutorial first but i'll try to help you.

First you need to create a button, then add a script and put this inside

extends Button

func _ready():
    connect("pressed",self,"_random")

func _random():
    randomize()
    set_text(str(round(rand_range(0,10))))

In the ready function you connect the pressed state with the _random function.

randomize() change the seed which will generate the random number.
And the last line set the button text with a random number from 0 to 10.

Hope it helps!

thank you, now it works.

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 Frequently asked questions and 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 [email protected] with your username.