|
|
|
|
Reply From: |
PickledPenguin |
You probably already know this stuff already, but just in case:
To send information (like an ID) with a signal, you have to declare the signal in the OperationCard script like this:
signal signal_name(*value you want to send*)
So in your case:
signal signal_name(ID)
where “ID” is the ID variable you want to send over.
Then when you want to send the signal, use:
emit_signal("signal_name", ID)
In the script that you want to recieve the signal, (in your case, the main script) put this line of code in the _ready() function:
OperationCard.connect("signal_name", self, "on_signal_function")
Somewhere in your script you can then declare a function with the name you put as the last parameter.
func on_signal_function(recieved_ID):
*do stuff*
And now you can transmit information across with signals.
As I said, you probably knew that already.
However, to answer your question, you don’t have to connect to all the OperationCard scenes in your main scene. When you connect to a signal, you are connecting to all of the instances of that scene in the main scene. So when any one of the 9 OperationCard scenes in the main scene is selected and emits its signal, the main script should pick it up, along with its unique ID.
Then, once the main script knows a card was selected and it knows its unique ID, it can do stuff like swap the card.
I hope this helps you!
I have created my scene by adding the object to it, not via code as an instance.
So i actually do have to connect to each scene entity to get the signal from it. If I only connect to one of them as below, I only get one signal printed out because only one is being received. it appears the singal is unique.
#connect to signals for selected
#connect emit_signal(“OC_pressed”, id, bSelected)
$NewOC1.connect(“OC_pressed”, self, “onCardSelected”)
#$NewOC2.connect(“OC_pressed”, self, “onCardSelected”)
#$NewOC3.connect(“OC_pressed”, self, “onCardSelected”)
#$NewOC4.connect(“OC_pressed”, self, “onCardSelected”)
#$NewOC5.connect(“OC_pressed”, self, “onCardSelected”)
#$OnDeckOC1.connect(“OC_pressed”, self, “onCardSelected”)
#$OnDeckOC2.connect(“OC_pressed”, self, “onCardSelected”)
#$OnDeckOC3.connect(“OC_pressed”, self, “onCardSelected”)
func onCardSelected(id, bSelected):
print ("Card ", id, bSelected)
pass
JoeSeki | 2021-01-13 21:26