How can i fix this error code "Invalid get index 'body_spritesheet' (on base: 'GDScript')" for character customization?

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


I am new to godot and coding, following an older tutorial on youtube trying to create a character customization screen with different changeable composite sprites for example like: hair, body, shirt etc.

Now the following error occurs when i try to run the player scene:

“Invalid get index ‘body_spritesheet’ (on base: ‘GDScript’)”

At the tutorial i’m following i’m at 5:50 for reference to where i stumble upon the error.

So far i have made 2 scripts, one attached to the Player.tscn scene and one that is not attached to anything. (I think this might be the problem, but i’m not sure since i’m new to godot)

Script 1 (

extends Node2D

onready var bodySprite = $CompositeSprites/Body
onready var hairSprite = $CompositeSprites/Hair
onready var eyesSprite = $CompositeSprites/Eyes
onready var shirtSprite = $CompositeSprites/Shirt
onready var pantsSprite = $CompositeSprites/Pants

const composite_sprites = preload("res://Assets/Player/CompositeSpritesheets/")

func _ready():
	bodySprite.texture = composite_sprites.body_spritesheet[0]
	hairSprite.texture = composite_sprites.hair_spritesheet[0]
	eyesSprite.texture = composite_sprites.eyes_spritesheet[0]
	shirtSprite.texture = composite_sprites.shirt_spritesheet[0]
	pantsSprite.texture = composite_sprites.pants_spritesheet[0]

Script 2 (

extends Node2D

var body_spritesheet = {
	0 : preload("res://Assets/Player/CompositeSpritesheets/Body_M.png"),
	1 : preload("res://Assets/Player/CompositeSpritesheets/Body_F.png"),

var hair_spritescheet = {
	0 : preload("res://Assets/Player/CompositeSpritesheets/Hair_01_Black_M.png"),
	1 : preload("res://Assets/Player/CompositeSpritesheets/Hair_02_Black_M.png"),

var eyes_spritesheet = {
	0 : preload("res://Assets/Player/CompositeSpritesheets/Eyes_01_Black.png"),
	1 : preload("res://Assets/Player/CompositeSpritesheets/Eyes_01_Brown.png"),

var shirt_spritesheet = {
	0 : preload("res://Assets/Player/CompositeSpritesheets/Shirt_01_Blue.png"),
	1 : preload("res://Assets/Player/CompositeSpritesheets/Shirt_02_Blue.png"),

var pants_spritesheet = {
	0 : preload("res://Assets/Player/CompositeSpritesheets/Pants_01_Blue.png"),
	1 : preload("res://Assets/Player/CompositeSpritesheets/Pants_02_Blue.png"),

This is how my Player.tscn tree looks like:

If anybody has some spare time to help me out with this error and perhaps explain what i might have done wrong so i can learn from it that would be greatly appreciated.
Also if any extra info is needed or screenshots, please ask me and i will provide.

Attach Script to CompositeSprites
Remove the const CompositeSprites line
Change the composite_sprite. to $CompositeSprites.

I think will work. I don’t have artwork to test. But I did with just using a dictionary of 0:yes, 1:no and got the same error as you did.

They might have removed standalone scripts? The error makes it seem like it doesn’t recognize the variable in the script.

MattMakingAGame | 2021-10-20 05:48

Thank you very much, this works :slight_smile:

IceTeaGreed | 2021-10-20 10:40