0 votes

HEY! i have a function trying to give a random number between 0 and the size on an array
for some reason it always prints out 39 (the array size is 64) here's the code:

func gunspawner():
    for x in range(global.map_size.x):
        for y in range(global.map_size.y):
            if global.map[x][y] == global.EMPTY:
    var choose_place = int(rand_range(0,available_slots_spawns.size()))
    gun.position = Vector2(global.map_coord[available_slots_spawns[choose_place][0]][available_slots_spawns[choose_place][1]])

thanks for taking the time to look at my code :)

in Engine by (120 points)

1 Answer

+1 vote
Best answer


have you tried to call function randomize() in your _ready() function?

by (50 points)
selected by

THANKS!! it worked perfectly

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.