Invalid get index 'face' (on base: 'GDScript')

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

I’m trying to convert a memory game into a Guess Who style game.

I’m trying to call two variables (face and back) from one script, Card.

(Card.gd)

extends TextureButton

class_name Card

var face
var back

(GameManager.gd)

extends Node

var f = Card.face
var b = Card.back

When I run the game to test it, the error in the title pops up, both for ‘face’ and ‘back’.

Does anyone know how to fix it?

:bust_in_silhouette: Reply From: Ev1lbl0w

You are trying to use Card as a singleton/autoload. You need to use an instanced Card object instead:

# GameManager.gd
extends Node

func something():
    ...
    # Get a node that inherits `Card` from the scene tree
    var my_card = $MyCard
    var f = my_card.face
    var b = my_card.back