How to call a signal from a global script in a scene script

Godot Version

4.3

Question

I started working with the plugin, and I don’t understand how to use signals

signal rewarded_ad(result)
signal interstitial_ad(result)

These are 2 signals responsible for advertising, the guide says “Calls the rewarded_ad(result) signal, the result variable contains one of the string values ​​’rewarded’, ‘closed’, ‘opened’ or ‘error’.”
but how can I get the result value in the code and connect the signal at all!
Please help!

If your signal is from a global script, then here is an example:

# global.gd
signal rewarded_ad(result)
signal interstitial_ad(result)

Everyone who wants to subscribe to the signal does this

func _ready():
   Global.rewarded_ad.connect(method_to_handle_the_signal)
func method_to_handle_the_signal(result):
   print(result)

this basically means that the script will listen to whenever this signal is emitted. Then as a reaction to that, it will call the method.

And everyone who wants to emit the Signal does this

Global.rewarded_ad.emit(result_variable)

Thank you very much! And another question: if I create a Node in the scene and attach a script to it and connect them through the Signals tab, will it be the same?

yes, this is no big deal.
The only thing you need to worry about is that the signal must exist before you connect or emit it. This means if you add a node to your scene that has a signal but everyone already “subscribed” to it, then this might not work.

In your case however, the signals are in a Global autoload, which is the best because it loads right from the start.

In my projects, I always have a “Connect” global script that has `all signals that I use for the game