Cannot pass a value of type "String" as "int".

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

I’m at the start of what, it’s increasingly clear, will be a long journey. I’m trying to pass a integer from child to parent, sounds easy right?

This is on the child:
extends classMovement
class_name classActiveSprite
var axis_X_active_sprite = 2

This is on the parent:
extends Node3D
class_name classMovement
var movement_x: int
var axis_X_active_sprite
func updateAxis() → void:
movement_x = get_child(“classActiveSprite”).str(axis_X_active_sprite)

The ‘Cannot pass…’ error occurs on the last parent line. Converting it with str() doesn’t even work, and anyway it’ll need converting back to an integer for the parent to use it.

I’m not comfortable declaring the same variable on both parent and child either, but it seems to need it.

Help greatly appreciated.

:bust_in_silhouette: Reply From: CollCaz

Take a look at the docs for get_child().

get_child() takes two arguments; The index of the child node you are trying to get and a bool either to include or exclude internal nodes that are added by the engine when running the game, You were passing in the name of the node instead, which is a string.

Now that you know why you were getting the error, here’s one way of implementing what you want

movement_x = find_child("node name in editor node tree").axis_x_active_sprite

Hope that helped!

Thanks CollCaz, I think I’ve got the hang of it a little better now. It’s the node’s name as it appears in the tree, as you say!

Curiously99 | 2023-05-26 17:22