Hi everybody,

im stuck:
I have a 3 variables

var choice1 = skillPool[randi() % skillPool.size()]
var choice2 = skillPool[randi() % skillPool.size()]
var choice3 = skillPool[randi() % skillPool.size()]

that each pick a random element from an array
var skillPool = [skill1, skill2, skill3, skill4, skill5]

and in my _ready I load up randomize:

func _ready():
	randomize()
	updateUI()

However: The variables still ALWAYS roll the same random number.

Can anybody help?

  • AspireMint replied to this.
  • jooscher
    Because "randomize()" is called AFTER you initiate choice1/2/3.
    So seed for random function is same everytime you run app.
    Fix:

    • initiate your variables in "_ready" function after "randomize()" line
      or
    • change "var" to "onready var" and put "randomize()" into _init() function
      or
    • do "randomize()" inside of global script - singleton

    jooscher
    Because "randomize()" is called AFTER you initiate choice1/2/3.
    So seed for random function is same everytime you run app.
    Fix:

    • initiate your variables in "_ready" function after "randomize()" line
      or
    • change "var" to "onready var" and put "randomize()" into _init() function
      or
    • do "randomize()" inside of global script - singleton