Page 1 of 1

bgaPerformAction not recognized

Posted: 23 July 2024, 15:40
by Matux38
Hi,

I started a card game. When a player clicks on a card, it triggers this event in the file "XXX.js". I made changes in setup and enteringState methods.
After that, there is my function :

Code: Select all

onCardClick: function(e) {
	e.preventDefault();
	e.stopPropagation();
	let card = e.target;
	let card_id = card.getAttribute('data-card-id');
	this.bgaPerformAction("cut", {
		card_id:  card_id
	});
}
I also wrote the function in "XXX.action.php" :

Code: Select all

public function cut(int $card_id) {
	// ...
}
But at this point, I only have the error:
TypeError: this.bgaPerformAction is not a function.

I looked at tutorials (reversi, etc...) and existing topics about this on this forum but I couln't figure out what I did wrong at this point.

Can you help me understand please?

Thanks :)

Re: bgaPerformAction not recognized

Posted: 23 July 2024, 15:43
by thoun
It's probably how you use onCardClick that is the issue (the context of "this" may then not be your game class as you expect).
Can you share the code about this call?

Re: bgaPerformAction not recognized

Posted: 24 July 2024, 08:37
by Matux38
Thanks !

I didn't think about it. I managed to solve it by fix the way the onCardClick is called.

Here is what I did if anyone encounters the same issue. The event was bind in onEnteringState only for clickable cards. But in the tutorial, the idea is that any card, even not clickable ones are bind to the event. And in the function onCardClick, now it's the correct "this" and there is a check if the event should really make the action or not.

Thanks for your help :)