Topic was automatically imported from the old Question2Answer platform.
Asked By
chantunRey
So I have a few dictionaries that are enemies and an array from I randomly choose one of their names. When I want to print, it gaves an error for being on base: string? Thanks in advance.
var enemies = ["rat", "dog", "puma"]
var currentEnemy
func _ready():
currentEnemy = enemies[randi()%3]
print(currentEnemy["HP"])
var rat = {
"nme": "Rat",
"HP": 2,
"attack": 1,
}
var dog = {
"nme": "Rat",
"HP": 6,
"attack": 2,
}
var puma = {
"nme": "Puma",
"HP": 4,
"attack": 8,
}
Thanks for your reply. I realized that it was that I declared the dictionary variables AFTER the function. thanks anyways
chantunRey | 2020-07-06 01:04
oh!
even if you change and declare de dictionary BEFORE gives you the same error, is a good practice to that but is the same, however, if it works for you now, great!
For me using the array for enemies and calling the dictionary keeps giving me error , I have to use my method.