![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | quizzcode |
Hey there,
I spent the past 4 hours trouble shooting this issue, googling and testing.
For the life of me, I can’t get it fixed. Which is why I’m here. Crossing fingers.
In short :
I have a button that send “race” argument to open a pop up node which has one button “buy it” sending the same argument.
The button to buy it, send the argument “race” to __on_open_info_race_buy(race) where I proceed with the purchase.
That seem simple.
But the button “buy it” will always send the information from the FIRST race I clic on.
So if i open race 3. then buy it. And clic on race 2. It will still try to buy race 3.
I have tested everything.
The moment i set the signal I printed the race before and after = all good.
The variable inside the signal send 100% the right race.
But when receiving it in __on_open_info_race_buy it will always be what was clicked first.
Here is some of my code.
MAIN SCENE :
4 buttons, sending each one unique ID : 1 2 3 4 to : _on_open_info_race(race)
In main scene script :
func _on_open_info_race(race): # BUY RACE
var race_info = Globals._race_info(race) #race informations
#display informations
$unlock_race/frame/title.text = str(race_info[0]) #Title of the race
$unlock_race/frame/description.text = str(race_info[1]) #Description of the race
$unlock_race/frame/btn/text.text = str(race_info[2]) #Cost of the race
$unlock_race.show() #display the pop up with these infos,
$unlock_race/frame/btn.connect('pressed',self, '_on_open_info_race_buy', [race, race_info[2]]) #Set up the button with race ID + cost.
pass
Ok so nothing special right ? Get the argument, read the informations depending of the race, set the button to signal : _on_open_info_race_buy(arg1,arg2)
Function _on_open_info_race_buy :
func _on_open_info_race_buy(race, cost): # Actually buying the race : Debit gold / add race to race owned.
print(race)
print(cost)
$unlock_race.hide()
in this function im doing nothing for the sake of this example.
The problem here is RACE and COST are only showing the argument the first time i load the 1st pop up with _on_open_info_race() - I dont even need to click the button.
example :
I open the pop up race id 2; i close it (just hide)
I open race 3. (It’s displaying race 3 information, so the argument race is good), I buy race 3.
But it shows that it’s buying race 2 and cost of race 2.
And I have no idea how to fix it.
Will record a video to maybe help with the explanation… Please let me know if i can provide any extra information.
EDIT : here is the video :
Human = 1 cost 0.
Orcs = 2 cost 2000
Nagas = 3 cost 3000
Demons = 4 cost 4000
As you can see, it will always show the first race i opened : 2/2000 (look into the console bottom left)
EDIT 2 :
I have tried to call the function manually rather than with my “pressed” button :
_on_open_info_race_buy(race, race_info[2])
And this works perfectly fine. No matter the race. So I’m assuming that there is something wrong wit my button ? Any idea ?