Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dragon20C |
This is the first time working with a class I am having issues understanding on how to use them correctly I have a class that is storing an array, and I want my other scripts to look up values from them but when I try to access a value from it, it says invalid get index “chart” base on gdscript,
here is the code:
extends Node
class_name TypeChart
var chart = [# Nor Fir Wat Ele Gra Ice Fig Poi Gro Fly Psy Bug Roc Gho Dra Dar Ste Fai
#Normal
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.5, 0, 1, 1, 0.5],
#Fire
[1, 0.5, 0.5, 1, 2, 2, 1, 1, 1, 1, 1, 2, 0.5, 1, 0.5, 1,2, 1],
#Water
[1, 2, 0.5, 2, 0.5, 1, 1, 1, 2, 1, 1, 1, 2, 1, 0.5, 1, 1],
#Electric
[1, 1, 2, 0.5,0.5, 2, 1, 1, 0, 2, 1, 1, 1, 1, 0.5, 1, 1],
#Grass
[1, 0.5, 2, 1, 0.5, 1, 1, 0.5, 2, 0.5, 1, 0.5, 2, 1, 0.5, 1, 0.5, 1],
#Ice
[1, 0.5, 0.5, 1, 2, 0.5, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, 0.5, 1],
#Fighting
[2, 1, 1, 1, 1, 2, 1, 0.5, 1, 0.5, 0.5, 0.5, 2, 0, 1, 2, 2, 0.5],
#Poison
[1, 1, 1, 1, 2, 1, 1, 0.5, 0.5, 1, 1, 1, 0.5, 0.5, 1, 1, 0, 2],
#Ground
[1, 2, 1, 2, 0.5, 1, 1, 2, 1, 0, 1, 0.5, 2, 1, 1, 1, 2, 1],
#Flying
[1, 1, 1, 0.5, 2, 1, 2, 1, 1, 1, 1, 2, 0.5, 1, 1, 1, 0.5, 1],
#Psychic
[1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 0.5, 1, 1, 1, 1, 0, 0.5, 1],
#Bug
[1, 0.5, 1, 1, 2, 1, 0.5, 0.5, 1, 0.5, 2, 1, 1, 0.5, 1, 2, 0.5, 0.5],
#Rock
[1, 2, 1, 1, 1, 2, 0.5, 1, 0.5, 2, 1, 2, 1, 1, 1, 1, 0.5, 1],
#Ghost
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.5, 1, 1, 2, 1, 0.5, 1, 1],
#Dragon
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 0.5, 0],
#Dark
[1, 1, 1, 1, 1, 1, 0.5, 1, 1, 1, 2, 1, 1, 2, 1, 0.5, 1, 0.5],
#Steel
[1, 0.5, 0.5, 0.5, 1, 2, 1, 1, 1, 1, 1, 2, 0.5, 1, 1, 1, 0.5, 2],
#Fairy
[1, 0.5, 1, 1, 1, 1, 2, 0.5, 1, 1, 1, 1, 1, 1, 2, 2, 0.5, 1]
]
A simple separate script
and this is where I use the class name to try to access the array
func Get_effectiveness(attack_type,defence_type):
if attack_type == Types.monster_type.none or defence_type == Types.monster_type.none:
return 1
var row : int = attack_type
var col : int = defence_type
print("row : " + str(row))
print("col : " + str(col))
return TypeChart.chart[row][col]