Check collisions in code and getting nodes out of the tree

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GunPoint
:warning: Old Version Published before Godot 3 was released.

So, i have two questions:
But before, i need to say, im a beginner programmer, with only 1-2 years of experience

  1. How i can get a node from the tree?
    The tree is:
    Game
    -button1
    -button2
    -player
    –playerSprite
    I want to get the node ‘button1’ (it is a textureFrame bcs it isnt exactly a button) from the player script, so when the player spawns first, the button is not visible
    I tried: get_tree().get_root().get_node(‘Game’).get_node(‘button1’).set_visible(false)
    But i get this error: “Attempt to call function ‘get_root’ in base ‘null instance’ on a null instance.”

AND How i can check collision between an area2D and the player inside the player’s script?
For example, i want to set the score to 1 when the player enters the area2D. But i want to do that in code

EDIT: I noticed Godot’s “for” loop is using the syntax “for … in …”
I learned just the simple “for” loop
example: for (i = 0; i < x; i++)
What does “for… in…” loop?

about the for loop thingy: for loops in godot are like for loops in python, you iterate through an array, not with an iteration like what you’ve learned… you can still set up a for loop the way you learned by using while loops

rustyStriker | 2017-10-12 18:42