This is a documentation for Board Game Arena: play board games online !

Practical debugging: Skirtumas tarp puslapio versijų

Iš Board Game Arena.
Pereiti į navigaciją Jump to search
No edit summary
16 eilutė: 16 eilutė:


* At first, I make sure that I can reproduce the needed game situation in one click. To do this, I use the "[[Tools_and_tips_of_BGA_Studio#Save_.26_restore_state|save & restore]]" function.
* At first, I make sure that I can reproduce the needed game situation in one click. To do this, I use the "[[Tools_and_tips_of_BGA_Studio#Save_.26_restore_state|save & restore]]" function.
* Another possibility for this is to place a "die('ok');" PHP statement right after the PHP I am developing/debugging. This way, the PHP request will stop immediately, nothing will be commited to the database, and the game initial situation will remains.
* Another possibility for this is to place a '''die('ok');''' PHP statement right after the PHP I am developing/debugging. This way, I make sure that every request will fail and then nothing will be commited to the database, anyway.
* Then, I use '''var_dump''' function to dump PHP variables and check what's wrong, until it works.


== Debugging my HTML/CSS layout ==
== Debugging my HTML/CSS layout ==

23:18, 29 sausio 2013 versija

This page gives you practical tips to debug your game during the development. Don't hesitate to share with us your difficulties in order we can improve this section.

Debugging my game when it cannot start

If your game don't start because of an error, you are probably in one of these situations:

  • There is a SQL error in your dbmodel.sql file.
  • You have a syntax error in your PHP file.
  • Your PHP "setup" - or any method used during the game initial states - generates an exception.

If the error is not explicitly displayed when you click on "Express start", you should check the "Gameserver error log" in the Studio backoffice.

Debugging my PHP game logic (or my view)

Most of the time, debugging PHP is quite easy. Here's what I do when I want to develop/debug some game logic that is triggered by some game action:

  • At first, I make sure that I can reproduce the needed game situation in one click. To do this, I use the "save & restore" function.
  • Another possibility for this is to place a die('ok'); PHP statement right after the PHP I am developing/debugging. This way, I make sure that every request will fail and then nothing will be commited to the database, anyway.
  • Then, I use var_dump function to dump PHP variables and check what's wrong, until it works.

Debugging my HTML/CSS layout

Debugging my Javascript game interface logic

Some frequent errors

What is the best way to debug?

On the server side (PHP), you can use one of these:

  • die(var_dump( $variable_to_inspect );
  • throw new BgaUserException(var_dump( $variable_to_inspect );

On the client side (Javascript), we recommand installing Firebug for Firefox (or using the 'Developer tools' with Chrome that have about the same functionalities), then:

  • console.log( variable_to_inspect ); will give you the object structure of the variable in the Firebug console, without blocking the execution. It's often a good idea to precede this call with a console.log( '### HERE ###' ); to find more easily the appropriate line in the console log.
  • alert( variable_to_inspect ); will popup what you wish and pause the execution until you click ok. This won't be useful for complex structures, only native types will get plainly displayed. But this is sometimes useful just with messages to make sure which way the execution goes.

In general for debugging, think of using the 'Save & restore state' functionality. It enables you to save the state of your game just before the issue you are investigating, then come back to that point with one click as many times as needed to understand what is going wrong. You can save up to 3 different states.

Some frequent errors

The following error occurs when launching the game "Fatal error during creation of database ebd_quoridor_389 Not logged."
Check that you didn't use $g_user or getCurrentPlayerId() in setupNewGame() function or in an "args" function of your state. As these functions are not consequences of a user action, there is no current player defined. As a general rule, you should use getActivePlayerId() and not getCurrentPlayerId(). See the presentation on the game state machine for more information.