0 votes


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 (Player.gd):

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/CompositeSprites.gd")

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 (CompositeSprites.gd):

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.

Godot version v3.3.4.stable.official
in Engine by (12 points)

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.

Thank you very much, this works :)

Please log in or register to answer this question.

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.