Page 1 of 1

Send to php

Posted: 17 April 2025, 21:12
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.

Re: Send to php

Posted: 18 April 2025, 00:14
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.

Re: Send to php

Posted: 18 April 2025, 11:05
by AxeCrazy
Did you include
use \Bga\GameFramework\Actions\Types\IntArrayParam;

in your game.php?
Just below the namespace definition?

Re: Send to php

Posted: 18 April 2025, 11:07
by AxeCrazy
And you should send them as a string like such from your js file

this.bgaPerformAction("actPlaycard", {
ids: this.selectedCardIds.join(',')
})

Re: Send to php

Posted: 30 April 2025, 10:20
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.