Invalid get index on base:2D Node

Godot Version

Godot 4.2.1

Question

Hello I’m new here so I hope this is the right place to ask

But recently I’ve been trying to teach myself the basics of godot script and been following along some tutorials
The part I’m stuck in about making a attack button UI for the player to choose from in a bareback rpg.
I’ve used a VBoxContainer with three buttons which are dragged into an array in the inspector. When I press play I should theorethically get the right attack names displayed in each button.

Instead I keep getting this error:
grafik
which is similair to an error the tutor in the tutorial is experiencing, except that for him it says “on base:Nil” and it gets resolved after he dragged the Player and enemy node into their respective slots in the inspector
(The script for that is called TurnManager and is on the root node of the scene called “BattleScene”)

here is the complete code for the TurnManager:

extends Node

@export var player_char : Node 
@export var enemy_char : Node 
var cur_char : Character 

@export var next_turn_delay : float = 1.0 

var game_over : bool = false 

signal character_begin_turn(character)
signal character_end_turn(character)

# Called when the node enters the scene tree for the first time.
func _ready():
	await get_tree().create_timer(0.5).timeout 
	begin_next_turn()


func begin_next_turn():
	if cur_char == player_char:
		cur_char = enemy_char
	elif cur_char == enemy_char:
		cur_char = player_char
	else:
		cur_char = player_char
		
	emit_signal("character_begin_turn",cur_char)
	
func end_current_turn():
	emit_signal("character_end_turn", cur_char)
	
	await get_tree().create_timer(next_turn_delay).timeout 
	
	if game_over == false:
		begin_next_turn()
	
	
func character_died(character):
	game_over = true
	
	if character.is_player == true:
		print("Game Over!")
	else:
		print ("You win!")

And for the UI:

extends VBoxContainer

@export var buttons : Array

# Called when the node enters the scene tree for the first time.
func _ready():
	get_node("/root/BattleScene").character_begin_turn.connect(_on_character_begin_turn)
	get_node("/root/BattleScene").character_end_turn.connect(_on_character_end_turn)
	
func _on_character_begin_turn (character):
	visible = character.is_player
	
	if character.is_player:
		_display_combat_actions(character.combat_actions)
		
func _on_character_end_turn(character):
	visible = false

func _display_combat_actions (combat_actions):
	for i in len(buttons):
		var button = get_node(buttons[i])
		
		if i < len(combat_actions):
			button.visible = true
			button.text = combat_actions[i].display_name
			button.combat_action = combat_actions[i]
		else: 
			button.visible = false

Right now the scene crashes completely if played so it would be great if someone could help

The script on the player and enemy nodes (the nodes that you have to drag into their slots in the inspector) are supposed to have an is_player variable. The error says that variable is missing.

Thank you! I checked the character script for that again and finally found the typo that caused the issue

1 Like