(iam new and i follow some tutorial to learn but iam stuck on something)

Godot Version

4.2.2

Question

Hi, iam extremly bad (and new) and i stuck here, can someone help me please ?

I got message of error from the “collid.advance_status()” and from “get_parent().get_node(“Label”).Text = get_parent().health_status[health]”

I’ve been stuck for so long

extends Node2D

var dir = Vector2(1, 0)

@export var bullet_speed = 400
# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	self.position += dir * delta * bullet_speed

	if ($RayCast2D.is_colliding()):
		var collid = $RayCast2D.get_collider().get_parent()
		if (collid.type == "PLAYER"):
			position += Vector2(2000, 2000)
			
			if (collid.health > 0):
				collid.health -= 1
			collid.advance_status()
		


func screen_exited():
	queue_free()
extends Node2D

var type = "PLAYER"

var health = 20

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
	self.position = get_global_mouse_position()



func advance_status():
	get_parent().get_node("Label").Text = get_parent().health_status[health]

What is the error? Seems like it could be about a missing node, what is your scene tree for the player?

Instead of var type = "PLAYER" you should declare a class_name.

extends Node2D
class_name Player

Then your if statement can fail gracefully

if ($RayCast2D.is_colliding()):
	var collid = $RayCast2D.get_collider().get_parent()
	if collid is Player:

When i try and a bullet touch my player, the “game” crash. (and i try with what you send me but didnt work either)

And i cant send you screen because iam new on the site (so i send you here… sorry :c)…

I have an “invalid get index ‘19’ (on base: ‘Array’)”

And those error :
W 0:00:00:0980 The parameter “delta” is never used in the function “_process()”. If this is intended, prefix it with an underscore: “_delta”.
UNUSED_PARAMETER
bullet_hell.gd:18

W 0:00:00:0981 open_internal: Case mismatch opening requested file ‘player.gd’, stored as ‘Player.gd’ in the filesystem. This file will not open when exported to other case-sensitive platforms.
<C++ Source> drivers/windows/file_access_windows.cpp:127 @ open_internal()

W 0:00:00:0986 EnemySpawn.gd:3 @ @implicit_new(): Case mismatch opening requested file ‘Enemy.tscn’, stored as ‘enemy.tscn’ in the filesystem. This file will not open when exported to other case-sensitive platforms.
<C++ Source> drivers/windows/file_access_windows.cpp:127 @ open_internal()
EnemySpawn.gd:3 @ @implicit_new()

Cool! so it says the health_status array does not have 19 elements in it. Can you show the script which defines health_status, I presume the parent of the player node? I am betting there is a simpler way to display health than an array.

Ok i send you ! (if you have advice for a simpler way i take it, its not gonna be like i want but i dont care if its work).
And when i set the right amount of Health (6) i have a new message :
“Invalid set index ‘Text’ (on base: ‘Label’) with value of type ‘String’.”

extends Node2D

var health_status = [
	"THE BANANA HIS LOST",
	"YOUR BANANA IS FALLING APART",
	"ALL BANANADE ARE FAILING",
	"YOUR BANANA HULL HAS BEEN BREACHED",
	"YOUR BANANA IS LIGHTLY DAMAGED",
	"YOUR BANANA IS AT FULL HEALTH"
]

# Called when the node enters the scene tree for the first time.
func _ready():
	Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass

So your health goes from 0 to 20, but your health status only has indexes 0 through 5 (6 total). If 20 will always be your maximum health, then we can use some math to convert from health to indexes in the player script. We get the percent of player’s health 0 to 1, then multiply that by how many indecies we have.

const MAX_HEALTH = 20
var health = MAX_HEALTH

func advance_status() -> void:
    var parent = get_parent()
    var highest_index = parent.health_status.size() - 1
    var health_percent = float(health) / MAX_HEALTH
    var health_index = int(highest_index * health_percent)

    var label = parent.get_node("Label")
    label.text = parent.health_status[health_index]

OMG IT WORK, i love you !!

Iam dumb (and iam new) so its not easy for me ty