Page 1 of 1
var_dump, php debugging - just does not work
Posted: 23 November 2020, 23:46
by developgame
Hi All
I am trying without any luck to use var_dump, dump, debug , trace in game.php
I am only able to do so successfully in function getAllDatas() . This will show up on the game screen
I have tried everything : Usually there is no syntax errors, but also nothing in BGA request&SQL logs.
var_dump( $my_variable );
self::dump( 'name_of_variable', $variable );
self::debug( $message ); // not found in BGA request&SQL logs
self::trace( $message ); //not found in BGA request&SQL logs
$this->dump("var")
"echo" just gives me syntax errors.
An example of the state function I am trying to put in some debug codes is
Code: Select all
function stNewHand()
{
$this->cards->shuffle( 'deck' );
do { //draw starting card
$this->cards->pickCardForLocation( "deck", "cardsontable" );
$an8 = $this->cards->getCardsOfTypeInLocation( NULL, "8", "cardsontable" );
$holder = array_shift( $an8 );
self::dump('holder ', $holder['type_arg']);
if ( $holder['type_arg'] == "8" )
{
$this->cards->moveAllCardsInLocation( "cardsontable" , "deck" );
$this->cards->shuffle( 'deck' );
}
} while ( $holder['type_arg'] == "8" );
$players = self::loadPlayersBasicInfos();
foreach ( $players as $player_id => $player )
{
$cards = $this->cards->pickCards( 5, 'deck', $player_id );
self::notifyPlayer($player_id, 'newHand', '', array ('cards' => $cards ));
}
}
Thanks a bunch for any help!!!!!!
Re: var_dump, php debugging - just does not work
Posted: 24 November 2020, 00:19
by jmcl99
Well self::trace certainly worked for me about 45 minutes ago and, like you, I have put some "proc entered" type messages into a state machine function and I can see the output in the BGA request and SQL logs.
It can be a bit tricky "seeing the wood from the trees" in those logs sometimes as they include all of the framework's logging and SQL updates some of which (e.g. the gamelog and notification trace) be quite large.
Re: var_dump, php debugging - just does not work
Posted: 24 November 2020, 11:04
by Bids
Have you tried to display the variable you want to show in a variable that is a scaler instead of an array?
for me it works when I do this:
Code: Select all
$holder = array_shift( $an8 );
$holderdisplay = $holder['type_arg'];
var_dump($holderdisplay);
die('ok');
I think you can also display the whole array by putting $holder in the var_dump, but I'm not sure about one element of an array. Someone with more experience should confirm this.
Re: var_dump, php debugging - just does not work
Posted: 24 November 2020, 11:55
by RicardoRix
My guess is that stNewHand() is never actually ever being called, so that's why you're not seeing anything.
You can call php functions from the chat window, just type stNewHand()
I use var_dump() and sometimes die();
complete arrays will work in var_dump();
I did use echo once when things got really hairy and wanted some nicer formatted output, for the most part var_dump() works perfectly.
die() will give a red message of 'Ajaxcall error: empty answer' when appropriate.
die() will also help to stop any DB final commit changes, much the same as the exceptions do like feException() and BgaUserException(); var_dump() alone will not stop the commits.
Re: var_dump, php debugging - just does not work
Posted: 24 November 2020, 15:09
by Victoria_La
If you code goes into infine loop (which is seems like case here) it may not work
Re: var_dump, php debugging - just does not work
Posted: 24 November 2020, 23:25
by developgame
jmcl99 wrote: ↑24 November 2020, 00:19
Well self::trace certainly worked for me about 45 minutes ago and, like you, I have put some "proc entered" type messages into a state machine function and I can see the output in the BGA request and SQL logs.
It can be a bit tricky "seeing the wood from the trees" in those logs sometimes as they include all of the framework's logging and SQL updates some of which (e.g. the gamelog and notification trace) be quite large.
thanks for your help, jmd99
I have always had this problem. I have been working around this by adding whatever I needed checking into result[] in getAllDatas() and then do a var_dump($result). var_dump only works in function getAllDatas()
Back in June, Another programmer told me he had this problem too.
When I do a var_dump outside getAllDatas(), I get the following error
ly_metasite.js:2 Unexpected error: Wrong formatted data from BGA gameserver 1 (method: createGame): JSON_ERROR_SYNTAX NULL
{"status":1,"data":true}
(anonymous) @ ly_metasite.js:2
When I use the following traces,
self::dump( );
self::debug( $message );
self::trace( $message );
self::warn( $message );
; /
I get no syntax errors, but I also cannot find the traces in BGA request&SQL logs . I even copy everything to notepad and do a search.
Thanks for your help!
Re: var_dump, php debugging - just does not work
Posted: 24 November 2020, 23:34
by developgame
Bids wrote: ↑24 November 2020, 11:04
Have you tried to display the variable you want to show in a variable that is a scaler instead of an array?
for me it works when I do this:
Code: Select all
$holder = array_shift( $an8 );
$holderdisplay = $holder['type_arg'];
var_dump($holderdisplay);
die('ok');
I think you can also display the whole array by putting $holder in the var_dump, but I'm not sure about one element of an array. Someone with more experience should confirm this.
Thanks for your help, Bids!
Thanks for your suggestion!
I tried it
Code: Select all
function stNewHand()
{
//$this->cards->moveAllCardsInLocation(null, 'deck' );
$this->cards->shuffle( 'deck' );
do { //draw starting card
$this->cards->pickCardForLocation( "deck", "cardsontable" );
$an8 = $this->cards->getCardsOfTypeInLocation( NULL, "8", "cardsontable" );
$holder = array_shift( $an8 );
$holderdisplay = $holder['type_arg'];
var_dump($holderdisplay);
die('ok');
if ( $holder['type_arg'] == "8" )
{
$this->cards->moveAllCardsInLocation( "cardsontable" , "deck" );
$this->cards->shuffle( 'deck' );
}
} while ( $holder['type_arg'] == "8" );
$players = self::loadPlayersBasicInfos();
foreach ( $players as $player_id => $player )
{
$cards = $this->cards->pickCards( 5, 'deck', $player_id );
self::notifyPlayer($player_id, 'newHand', '', array ('cards' => $cards ));
}
}
and got the following error when I used var_dump($holderdisplay); die('ok');
Unexpected error: Wrong formatted data from BGA gameserver 1 (method: createGame): JSON_ERROR_SYNTAX NULL
ok
When I just had var_dump($holderdisplay); I got the following error :
ly_metasite.js:2 Unexpected error: Wrong formatted data from BGA gameserver 1 (method: createGame): JSON_ERROR_SYNTAX NULL
{"status":1,"data":true}
Thanks for your help!
Re: var_dump, php debugging - just does not work
Posted: 24 November 2020, 23:55
by developgame
RicardoRix wrote: ↑24 November 2020, 11:55
My guess is that stNewHand() is never actually ever being called, so that's why you're not seeing anything.
You can call php functions from the chat window, just type
stNewHand()
I use var_dump() and sometimes die();
complete arrays will work in var_dump();
I did use echo once when things got really hairy and wanted some nicer formatted output, for the most part var_dump() works perfectly.
die() will give a red message of 'Ajaxcall error: empty answer' when appropriate.
die() will also help to stop any DB final commit changes, much the same as the exceptions do like feException() and BgaUserException(); var_dump() alone will not stop the commits.
Thanks for your help, RicardoRix!
Thank you for your information about calling php functions from the chat window and info about die(). This is very helpful!
I have always had this problem with var_dumps and traces in BGA studio. I have been working around this by adding whatever I needed checking into result[] in getAllDatas() and then do a var_dump($result). var_dump only works in function getAllDatas()
When I do a var_dump outside getAllDatas(), I get the following error
ly_metasite.js:2 Unexpected error: Wrong formatted data from BGA gameserver 1 (method: createGame): JSON_ERROR_SYNTAX NULL
{"status":1,"data":true}
(anonymous) @ ly_metasite.js:2
When I use the following traces,
self::dump( );
self::debug( $message );
self::trace( $message );
self::warn( $message );
; /
I get no syntax errors, but I also cannot find the traces in BGA request&SQL logs . I even copy everything to notepad and do a search.
Thanks again for your help!
Re: var_dump, php debugging - just does not work
Posted: 24 November 2020, 23:59
by developgame
Victoria_La wrote: ↑24 November 2020, 15:09
If you code goes into infine loop (which is seems like case here) it may not work
Thanks Victoria_la for your help!
I have always had problems using var_dumps, echos and traces with BGA studio, even if I am not using loops.
I have been working around this by adding whatever I needed checking into result[] in getAllDatas() and then do a var_dump($result). var_dump only works in function getAllDatas()
When I do a var_dump outside getAllDatas(), I get the following error
ly_metasite.js:2 Unexpected error: Wrong formatted data from BGA gameserver 1 (method: createGame): JSON_ERROR_SYNTAX NULL
{"status":1,"data":true}
(anonymous) @ ly_metasite.js:2
When I use the following traces,
self::dump( );
self::debug( $message );
self::trace( $message );
self::warn( $message );
; /
I get no syntax errors, but I also cannot find the traces in BGA request&SQL logs . I even copy everything to notepad and do a search.
thanks again for your help!