How to debug Puzzles: Difference between revisions
No edit summary |
|||
| Line 15: | Line 15: | ||
Your scenario behaves odd, but there is no errors in the browser console? Just insert the [https://www.soft8soft.com/docs/manual/en/puzzles/System.html#print_to_console print to console] puzzle in the places you need to check with some meaningful data passed as input. | Your scenario behaves odd, but there is no errors in the browser console? Just insert the [https://www.soft8soft.com/docs/manual/en/puzzles/System.html#print_to_console 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 [https://www.soft8soft.com/docs/manual/en/puzzles/Objects.html#set_transform set transform] puzzle. Once you've done with | 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 [https://www.soft8soft.com/docs/manual/en/puzzles/Objects.html#set_transform set transform] puzzle. Once you've done with your scenario, you see that the object is not placed correctly. What should you do first? Yep, open the browser console! Unfortunately there are no issues there: | ||
[[File:debugging_with_print_to_console_before.webp|1000px]] | [[File:debugging_with_print_to_console_before.webp|1000px]] | ||
This means you should insert the "print to console" to your scenario | This means you should switch to plan B and insert the "print to console" puzzle to your scenario. But where? At the first glance you should place it just before the actual object positioning takes place. Here we go: | ||
[[File:debugging_with_print_to_console_after.webp|1000px]] | [[File:debugging_with_print_to_console_after.webp|1000px]] | ||
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 fixing | Once you've done with bug fixing, remove "print to console" puzzle to prevent cluttering of the browser console. | ||
== Summary == | == Summary == | ||
Revision as of 15:55, 21 March 2026
This short 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 on how to open one).
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:
Yep, 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? Yep, open the browser console! Unfortunately there are no issues there:
This means you should switch to plan B and insert the "print to console" puzzle to 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, remove "print to console" puzzle 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 and carefully read its output