Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Zakuree |
extends Node2D
var fN = ["Michael ", "Malcolm ", "Mason ", "Matthew ", "Marty ", "Marshall "]
var lN = ["Green", "Gatry", "Gunther", "Grey", "Geller", "Galloway"]
func genPlayers(amount):
for n in range(amount):
var player = {
"name": fN[randi() % fN.size()] + lN[randi() % lN.size()],
"age": randi()%10+18
}
return player
func _ready():
randomize()
print(genPlayers(15))
As you can see here, I’m trying to randomize 15 random people, with a randomized name and age. Using genPlayers(15)
I call for a randomized name and age 15 times. However, when it gets printed from print(genPlayers(15))
, it only prints one person:
Why is this happening? If I do print(player)
from inside the function, it prints all 15. But returning the player
value and then printing it in the _ready()
function is only printing 1.