"Invalid Set Index" error - trouble understanding why this is happening

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cowhand214
:warning: Old Version Published before Godot 3 was released.

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.

IdlePlayer.gd

extends "Base.gd"

func enter(entity):
	entity.set_fixed_process(false)
	entity.set_process_input(true)

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
		entity.transition_to(state)

Moving.gd

extends "Base.gd"

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

****snip****

Base.gd

extends Node

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

func enter(entity):
	pass

func input(entity, event):
	pass

func update(entity, delta_time):
	pass

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.

2D||!2D | 2017-05-15 05:31

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.get_node(“…”), use self.get_parent() instead. The self is not needed ither.

rredesigns | 2017-05-15 05:38

updated OP to show codes better.

volzhs | 2017-05-15 07:01

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 ^^ ).

eons | 2017-05-15 19:10

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.

cowhand214 | 2017-05-16 03:29