+1 vote

Hello. I've been following the rogue-like tutorial found here and am currently on the fourth installment in that series implementing player movement in response to input.

I'm getting an "invalid set index" error when attempting to set a property from within one of my scripts. I'm having trouble determining whether the problem is that I'm retrieving a the node on which I wish to set the property incorrectly or it is the correct node but it isn't structured properly.

I'm hoping a fresh set of eyes can will be able to see what I'm doing wrong. I'm majestically inexperienced with Godot/GDScript so it may be something really simple.

The error is at the bottom of the IdlePlayer.gd input() function on the line:
state.delta_xy = delta_xy

Here are the relevant code files. I hope it's not too much to paste in but I figured more was better than less. Please let me know what other information I can provide.


extends "Base.gd"

func enter(entity):

func input(entity, event):
    var delta_xy
    var isMoving = false
    if (event.is_action_pressed("ui_right")):
        delta_xy = entity.UNIT_RIGHT
        isMoving = true
    elif (event.is_action_pressed("ui_down")):
        delta_xy = entity.UNIT_DOWN
        isMoving = true
    elif (event.is_action_pressed("ui_left")):
        delta_xy = entity.UNIT_LEFT
        isMoving = true
    elif (event.is_action_pressed("ui_up")):
        delta_xy = entity.UNIT_UP
        isMoving = true

    if isMoving:
        var state = self.parent.get_node("Moving")
        state.delta_xy = delta_xy


extends "Base.gd"

export var duration = 0.25
var _time_elapsed = 0
var _pos_start
var delta_xy



extends Node

onready var parent = self.get_node("..")

func enter(entity):

func input(entity, event):

func update(entity, delta_time):
in Engine by (18 points)
edited by

There are many inconsistencies with underscores in your code. In particular the delta_xy, deltaxy, setfixedprocess, setprocessinput, and isactionpressed.

EDIT - sorry, was reading this on my phone and misread it and merged your moving.gd and base.gd in my head. Deleting 2 sentences that will cause confusion.

Tidy those up and report back.

Your logic is insanely messy. Three scripts just for moving?? What's the difference between deltaxy and delta_xy?

I'm surprised you only got that error. xD

One quick tip. Don't use self.getnode(".."), use self.getparent() instead. The self is not needed ither.

updated OP to show codes better.

Check all variable values when you get that error, it is trying to set a variable that does not exists in state (why does Base not have delta_xy?).

ps: an extra tip, don't use "self" at all xD (unless you need to trigger a setter/getter, this is just an aesthetic comment ^^ ).

Thank you for the replies. I've been at work/traveling all day. I'll try to make the clarifications requested tomorrow morning.

To be clear, the logic/structure is from the tutorial. Part of the reason I think I'm having trouble with the error is in fact that I'm having trouble following the code structure compounded by unfamiliarity with Python-esque/duck typed languages and so I'm wanting to step through it in action to better understand.

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.