bgaPerformAction not recognized

Game development with Board Game Arena Studio
Post Reply
User avatar
Matux38
Posts: 10
Joined: 03 July 2024, 08:17

bgaPerformAction not recognized

Post 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 :)
User avatar
thoun
Posts: 1620
Joined: 10 December 2020, 22:25

Re: bgaPerformAction not recognized

Post 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?
User avatar
Matux38
Posts: 10
Joined: 03 July 2024, 08:17

Re: bgaPerformAction not recognized

Post 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 :)
Post Reply

Return to “Developers”