var powerups = powerUpDict.values()
var choice = powerups[randi() % powerups.size() + 1]
for key in choice:
printt(key, " - ", choice[key])
That was exactly what I needed to figure it out. Much appreciated.
For anyone in the future. Here is how I have it working now:
var powerUpDict = {
"speedUpBat" : {
imageToUse = "speedUpBat.png",
batSpeedChange = 10,
ballSpeedChange = 0,
freezeBat = false,
doublePoints = false,
spawnRandomPowerup = false,
},
"slowDownBat" : {
imageToUse = "slowDownBat.png",
batSpeedChange = -10,
ballSpeedChange = 0,
freezeBat = false,
doublePoints = false,
spawnRandomPowerup = false
}
}
#random dude
randomize()
#pick a random sub dictionary from within the main dictionary
var powerups = powerUpDict.values()
var theChosenOne = powerups[randi() % powerups.size()]
#load the texture stored in the sub dictionary as an object and assign it to the node as the new texture
var loadString = "res://textures/"+theChosenOne.imageToUse
var imageToUse = load(loadString)
get_node("powerUpSprite").set_texture(imageToUse)
Robster | 2017-04-03 22:32
Just a note to this, my example was for readability. If you ever do this with huge dictionaries, it would be more optimal to go with derblitzmann’s suggestion for picking the key. An array of keys is likely faster than an array of dictionaries.