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:
                available_slots_spawns.append([x,y])
    var choose_place = int(rand_range(0,available_slots_spawns.size()))
    print(choose_place)
    gun.position = Vector2(global.map_coord[available_slots_spawns[choose_place][0]][available_slots_spawns[choose_place][1]])
    add_child(gun)
    checkForWeapons()

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

in Engine by (120 points)

1 Answer

+1 vote
Best answer

Hi,

have you tried to call function randomize() in your _ready() function?
https://docs.godotengine.org/en/stable/classes/class_randomnumbergenerator.html

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 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.