Way to add more information in 1 variable?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Giffi

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}
:bust_in_silhouette: Reply From: 01lifeleft

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

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():

estebanmolca | 2020-01-20 18:58