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 (31 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 (824 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 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 webmaster@godotengine.org with your username.