How to debug Puzzles
This short but important how-to explains how to find and fix bugs in your Puzzles scenarios.
Look for errors in the browser console
If you execute Puzzles incorrectly, e.g. by passing invalid inputs, they will fail to work and print the explanation in the browser console (see here for instructions to open it).
Check out the following example that explain the idea. Consider you need to replace texture on some of your models with the replace texture puzzle, but nothing happens once you execute this puzzle. By looking in the browser console you'll find the cause of this issue immediately:
It says you've specified invalid path to the texture! Fix the path and reload the app to see that the issue has gone.
Use print to console puzzle
Your scenario behaves odd, but there is no errors in the browser console? Just insert the print to console puzzle in the places you need to check with some meaningful data passed as input.
Let's explain it with the following example. Consider you need to calculate a position with some function ("calc object position") and then place some object to this position with the set transform puzzle. Once you've done with your scenario, you see that the object is not placed correctly. What should you do first? Yes, you should open the browser console! Unfortunately, there are no errors printed there:
This means you should switch to plan B and insert the print to console puzzle into your scenario. But where? At the first glance you should place it just before the actual object positioning takes place.
Here we go:
By running this code we finally see that the position returned by the "calc object position" is not correct. In our specific case it has zero values for all 3 coordinates (XYZ). Now it's time to review the "calc object position" and check for possible errors happening in that function. If necessary, insert as many "print to console" puzzle as needed to find the cause of the issue.
Once you've done with bug fixing, don't forget to remove the "print to console" puzzle(s) to prevent cluttering of the browser console.
Summary
Ability to find bugs in Puzzles and resolve them quickly is the first skill you should master. Let's repeat the algorithm:
- open the browser console and look for errors
- insert print to console in the right place/places and carefully read their output