Problems with disabling nodes

Godot Version

4.2

Question

extends Node2D

var Joys = []
var Players = []

# Called when the node enters the scene tree for the first time.
func _ready():
	var PlayerBase = get_node("Player_")  # Assuming you have a node named "Player_"
	Joys = Input.get_connected_joypads()

	for PlayerID in Joys:
		if Joys.count(PlayerID) == 0:
			disable_and_hide_node(get_child(PlayerID))

func _process(delta):
	print(has_node("Player2"))

func disable_and_hide_node(node:Node) -> void:
	node.process_mode = 4 # = Mode: Disabled
	node.hide()

func enable_and_show_node(node:Node) -> void:
	node.process_mode = 0 # = Mode: Inherit
	node.show()

Im trying to make it so if there is a controllers 0 and 1, the 2 player disbles beacuse there is not a controller to control him
image

print(has_node("Player2")) seems like a strange thing to do, because the child-node is called “2” and not “Player2”. Can you please describe the problem you are having more clearly?

extends Node2D

var Joys = []
var Players = []


# Called when the node enters the scene tree for the first time.
func _ready(): # Assuming you have a node named "Player_"
	Joys = Input.get_connected_joypads()
	Players = get_children()
	for PlayerID in Joys:
		if Players.has(PlayerID):
			print(PlayerID)

func _process(delta):
	pass

i made this new code but now i have the problen of, How to search an array for an object only based on the name. So no this: “:<CharacterBody2D#26944210119>”
Only this [0, 1, 2, Camera2D]

[0:<CharacterBody2D#26944210119>, 1:<CharacterBody2D#27011318995>, 2:<CharacterBody2D#27078427863>, Camera2D:<Camera2D#27145536731>]

You can get the name of a node by accessing its name property. Please see: Node — Godot Engine (stable) documentation in English