Hi, I'm coding in GDScript, and am making a top-down shooter. I have all the shooting and movement down, but I want to implement a few other things to my game. I will look up some youtube tutorials on these, so on a few of them I'll probably have to answer by the time somebody gets back to me. 1) I would really like to add different levels to my game. 2)I would really like to know how to make a sprite change costume ON COMMAND rather than on a specific animation schedule. 3) I want to add in a main menu, so I need a way of detecting a sprite being clicked. Finally: 4)A function that I used ALOT when I used scratch- which is allowing sprites to send messages to one another, meaning that they can carry out attached code to the message when they recieve that specific message.

Hope someone can get back to me with a few of the answers I need. Thanks :)

1) You can use different scenes, and then change between them using get_tree().change_scene("res://path_to_scene_here.tscn") or get_tree().change_scene_to(packed_scene_here). Here's the documentation for change_scene.

2) Not quite sure what you are asking here, to be honest. If the costume is an additional sprite, you can have it appear and disappear whenever by changing its visibility property. If it is a different texture and you are using sprite-sheet-based animation, you can probably just swap the texture being used by the sprite via code, and so long as both textures have the same animations in the same grid positions in the image.

3) There is a tutorial on the documentation for adding a main menu. I would recommend using Control-based nodes though, not Sprites, simply because then you can take advantage of the layout options Control-based nodes provide.

4) Godot signals basically do this (documentation), you just need to connect them together. Then you can send whatever you need to another object through the signals. There is also the propagate_call function (documentation) if you want to call a function on a node and all its children recursively, though from a performance perspective, this may not be ideal due because the function has to iterate through every child regardless of whether it has the function or not.

Thanks for the response, TwistedTwigleg. 1) Yeah, I've tried calling back scenes using get_tree().change_scene_to(), but it then doesn't run the code inside my player KinematicBody2D, so I enter the scene and it just leaves me with a lifeless sprite that won't move. 2)I think you can actually use hide() or show() in code to make sprites hide or show on command. I looked it up, but you can confirm if this works or not. 3) I made a main menu that knows when a button is clicked, and then (as I mentioned in my first thing), it leaves me with a lifeless sprite. 4) I have about 3 tutorials on how to send and receive signals XD, but if you could elaborate with what code I should be writing if I want to send or receive a specific message. I looked it up and it talked about a whole bunch of confusing things- I'll put it all here: Emitting a signal from Primary.gd and receiving it in Secondary.gd can be done in the following way: first, you would have your two scripts written like this:

Primary.gd

extends Node

signal the_signal

# Then whatever code...
Secondary.gd

extends Node
# Note: inheriting Primary is not necessary for the signal to be received,
# so for this example I will not inherit it

func on_state_changed():
    print("Update!")

Then you would have each of these scripts in two nodes, anywhere in your scene. Now, for Secondary to receive the signal, it has to be connected with Primary.

You can do this from the scene tree editor: select the Primary node, then click on the Node dock. This dock should show all signals your node can emit, and you should see the_signal in them. Double-click on it, a dialog will open asking you which node should receive the signal. Select Secondary, and write the name of the function to call ("Method in Node"): on_state_changed, validate and they should be connected.

There is another way to do this connection, with code, using the _ready function. For example, in Secondary.gd, you can do this:

func _ready():
    var primary = get_node("relative/path/to/Primary")
    primary.connect("the_signal", self, "on_state_changed")
or, if you prefer doing it from Primary.gd:

func _ready():
    var secondary = get_node("relative/path/to/Secondary")
    connect("the_signal", secondary , "on_state_changed")
Finally, for this signal to do something, you have to emit it.
A simple way to test if it works is to emit the signal when you click a mouse button. To test this, you can use the _input function in Primary.gd:

func _input(event):
    if event is InputEventMouseButton and event.pressed:
        emit_signal("the_signal")

Thanks again for the response, I love learning new coding languages, frustrating and difficult though they are!

2 years later