This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

-2d node

I create a function to player shoot

const bullet_pre = preload("res://Bullet.tscn") 

func create_bullet(): var bullet = bullet_pre.instance() bullet.global_position = global_position get_parent().add_child(bullet)

But when i add a print(bullet.position.x) just print the inicial moment when the bullet was created, print only once time and no more.
Others variables that change also no print.
I want to know how to print every time how to objects already loaded in node

in Engine by (33 points)

1 Answer

0 votes
Best answer

Hi Torico, I think that's how it should be. A print statement on the end of your function will only be called once. Also, when a functions run is finished all local variables (like your bullet variable) will be erased. If you want to constantly print the states of all bullets of your scene you could add them to a group (bullet.add_to_group("Bullets")) and then do something like

func _process(delta):
    for bullet in get_tree().get_nodes_in_group("Bullets"):
        print(bullet.name, " is at ", bullet.position.x)

Hop it helps. Feel free to ask more if not.

by (864 points)
selected by

That's right, it worked, thank you so much!!!!!!!!!

THANK YOU!
After hours of looking for an answer to this, you solved it!
I only made an account on here to thank you,
I really apricate it,
chunkyPug

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.