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

Practical debugging

จาก Board Game Arena
รุ่นแก้ไขเมื่อ 22:53, 29 มกราคม 2556 โดย Sourisdudesert (คุย | ส่วนร่วม) (Created page with " 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. == Debu...")
(ต่าง) ←รุ่นแก้ไขก่อนหน้า | รุ่นแก้ไขล่าสุด (ต่าง) | รุ่นแก้ไขถัดไป→ (ต่าง)
ไปยังการนำทาง ไปยังการค้นหา

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)

Debugging PHP is most of the time easy

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.