Send to php

Game development with Board Game Arena Studio
Post Reply
User avatar
BenjaRocks
Posts: 2
Joined: 04 February 2024, 18:07

Send to php

Post by BenjaRocks »

Sorry!
I need help 😦

I have in my x.js
const selectedCardIds = [8, 12, 25]; // Array of integers
this.bgaPerformAction('actPlayCard', {
cardIds: selectedCardIds // Sends as an array
});


In my game.php

public function actPlayCard(#[IntArrayParam(name: 'cardIds')] array $cardIds)
{
// Debugging the received data
error_log('Received cardIds: ' . print_r($cardIds, true));

// Continue with the game logic
}

But i have errors 😦

I wouldn't ask for help, but I've been stuck on this topic for 4 days.

I want to send the card IDs through JS and have PHP, for example, log that it has received them.

I've tried many ways to send the information and all of them give me an error.


The error :

Server syntax error:
Fatal error: Uncaught Error: Attribute class "Bga\Games\AceOfSpadesP\IntArrayParam" not found in /var/tournoi/release/tournoi-250416-0910-gs/www/Bga/GameFramework/GameAction.php:482 Stack trace: #0 /var/tournoi/release/tournoi-250416-0910-gs/www/Bga/GameFramework/GameAction.php(482): ReflectionAttribute->newInstance() #1 /var/tournoi/release/tournoi-250416-0910-gs/www/Bga/GameFramework/GameAction.php(584): Bga\GameFramework\GameAction->bgaGetParameterValue(Object(ReflectionParameter), '...') #2 [internal function]: Bga\GameFramework\GameAction->Bga\GameFramework{closure}(Object(ReflectionParameter)) #3 /var/tournoi/release/tournoi-250416-0910-gs/www/Bga/GameFramework/GameAction.php(584): array_map(Object(Closure), Array) #4 /var/tournoi/release/tournoi-250416-0910-gs/www/include/webActionCore.inc.php(208): Bga\GameFramework\GameAction->performServerAction('...') #5 /var/tournoi/release/tournoi-250416-0910-gs/www/index.php(262): launchWebAction('...', '...', '...', false, false, NULL, true, false) #6 {main} thrown in /var/tournoi/release/tournoi-250416-0910-gs/www/Bga/GameFramework/GameAction.php on line 482





I've tried everything, there's just no way.

If you have a working example, that would be great.
User avatar
RicardoRix
Posts: 2540
Joined: 29 April 2012, 23:43

Re: Send to php

Post by RicardoRix »

Looks good, but it says you can ommit the name attribute if it's the same, so the simpler:

Code: Select all

public function actDiscardCards(#[IntArrayParam()] array $ids)
The action function should be prefixed by "act" and match the names specified in the "possibleactions" field on the state file.
Do you have the possibleactions part?

Does a simpler type work for you, like just a single int ?

This is all new BGA framework stuff, and judging by the error log, the 'ReflectionParameter' seems to be kicking in, but has a distinct problem with IntArrayParam.
User avatar
AxeCrazy
Posts: 90
Joined: 15 March 2014, 01:07

Re: Send to php

Post by AxeCrazy »

Did you include
use \Bga\GameFramework\Actions\Types\IntArrayParam;

in your game.php?
Just below the namespace definition?
User avatar
AxeCrazy
Posts: 90
Joined: 15 March 2014, 01:07

Re: Send to php

Post by AxeCrazy »

And you should send them as a string like such from your js file

this.bgaPerformAction("actPlaycard", {
ids: this.selectedCardIds.join(',')
})
Whales Entertainment
Posts: 7
Joined: 26 August 2024, 08:38

Re: Send to php

Post by Whales Entertainment »

Hi, we are a board game publisher and competent in developing software. We have developed two projects so far - The Nine Sons Of The Dragon and Safari Witness. More importantly, it also depends on the game rules and the presentation you wish to make. Let me know if you have any further needs.
Post Reply

Return to “Developers”