Zenva course build a micro RPG, get index 'is_player' (on base:Nil). and trouble with display name

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

I’m having trouble finding out what I did wrong when trying to display the resource names on the combat actions with the display_name function and when I do start keep saying
invalid get index 'is_player(on base: ‘Nil’). Also in PlayerUI character is null for whatever reason`extends VBoxContainer

character script ###################################

extends Node2D
class_name Character

@export var is_player :bool
@export var cur_hp :int = 25
@export var max_hp: int = 25
@export var opp : Node

@export var combat_actions :Array



@onready var health_bar: ProgressBar = get_node("Health_Bar")
@onready var health_Text: Label = get_node("Health_Bar/Health_Text")

@export var visual : Texture2D
@export var flip_visual : bool


# Called when the node enters the scene tree for the first time.
func _ready():
	$Sprite.texture = visual
	$Sprite.flip_h =flip_visual
	
	
	
	
	get_node("/root/battle_scene").character_begin_turn.connect(_on_character_begin_turn)
	health_bar.max_value =max_hp

func take_damagae(damage):
	cur_hp -= damage
	_update_health_bar()
	
	if cur_hp <= 0:
		get_node("/root/battle_scene").character_died(self)
		queue_free()

func heal (amount):
	cur_hp += amount
	
	if cur_hp > max_hp:
		cur_hp = max_hp
	_update_health_bar()

func _update_health_bar():
	health_bar.value = cur_hp
	health_Text.text = str(cur_hp, "/", max_hp)
	
func _on_character_begin_turn(character):
	pass
	
func cast_combat_action(action):
	pass

CombatAction Script#####################################

extends Resource
class_name CombatAction

@export var display_name = "Action (x DMG)"
@export var damage : int = 0
@export var heal : int = 0

CombatActionsButton script

extends Button

var combat_action : CombatAction

func _on_pressed():
	get_node("/root/battle_scene").cur_char.cast_combat_action(combat_action)

PlayerUI script###################################

extends VBoxContainer

@export var buttons : Array


func _ready():
	get_node("/root/battle_scene").character_begin_turn.connect(_on_character_begin_turn)
	get_node("/root/battle_scene").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

Turn_Manager script###########################################

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.75).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")

Edited to fix forum code formatting…

jgodfrey | 2023-06-21 15:31