How do you change properties of nodes in gdscript

im trying to get into more gdscript so i think knowing how to change properties of items trough code would be a good starter (at the very least)

1 Like

What properties are you talking about? Properties of an item are stored in the item so you can use item.property to access it.
ex: item.position.x = 0
would set the x position of the item to zero.

1 Like

thats what im talking about, im also half trying to know how to access nodes in scenes since i dont really know how

1 Like

Nodes are accessed using a dollar sign. You can see this by dragging the node from the tree onto the script.
It sounds like you’re really starting from scratch so you might want to take a look at a tutorial. This one is very in depth.
The ultimate introduction to godot 4

1 Like

how would i access the nodes inside the nodes and/or the parent node?

1 Like

Are you talking about children nodes? You can get the children with get_node() or $ as a shortcut.

1 Like

what about the parent or the node of the script?

1 Like

you can get parent with “get_parent()” and you can access properties of the node the script is on directly by name.

1 Like

can you do “$node.get_parent()”

1 Like

You could, but that would just refer to the current node.

1 Like

why would it be the current node

1 Like

$node means get the child of the current node that has the name of the node. .get_parent() means get the parent of the previous node, and the parent is just the original node.

1 Like

how would i refer to the current node without doing $node.get_parent()

1 Like

you can use self. But don’t do something like “self.position”, you can just use “position” in that case.

1 Like

so you just type “position” and done?

1 Like

i tried using position, there is an error saying “identifier ‘position’ is not declared in the current scope.” could you help me?

position is a property of classes that inherit from Node2 or Node3 (and maybe some others).

In your script at the top there should be something like:
extends ...

Extends means they inherit their properties and functions from something.
If you extend from Node (not Node2D or 3D) there will be no position.

From your questions I really recommend to check out the
beginner tutorials, there is one for 2d and one for 3d.
They are pretty good to get started. :slight_smile: