0 votes

I'm making my first game on the engine, it's a pokemon battle scene and i need to know these things about 1 pokemon,TYPE HP ATK SPATK DEF SPDEF SPEED is there good way to add them and easily accessible? for attacks i need to know TYPE POWER PRIORITY.

how i have done it so far. I have made function for every thing that i need about pokemon, for example power for each attack

func get_move_damage(move): #-1 = non damaging move

if move == tackle:
    return 40 # normal
elif move == protect:
    return -1 # normal
elif move == hyperbeam:
    return 150 # normal

but the thing is have to have these kind of function for almost everything.

how i would like to have it.

squirtle = {hp:151,atk:110,def:128,spatk:112,spdef:127,spd:104}
tackle = {type:normal,pwr:40}
in Engine by (12 points)

1 Answer

0 votes

You can use Dictionary to store multiple values paired with each unique keys.

var stats = {"hp": 150, "atk": 10, "def": 5}

Now you can access any value of the dictionary variable using their key name:

func get_atk():
   return stats["atk"]

As new user, looking at the syntax might help you get a better start: GDScript basics

by (14 points)

To add, you can also use dictionaries within dictionaries:

var STATS={
"TYPE" : 1,
"HP" : 100, 
"ATK" : {"TYPE" : "primary", "POWER" : 50, "PRIORITY" : 1}, 
"SPATK" : 0, 
"DEF" : {"TYPE" : "active", "POWER" : 20}, 
"SPDEF" : 0, 
"SPEED" : 100
}

func _ready():
    print(STATS["HP"])
    print(STATS["ATK"]["TYPE"])
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.