|Python Tutorials||(back to the list of tutorials)|
add_library('igeo') size( 480, 360, IG.GL ) i=j
The problem of the code above is actually the missing semicolon (;) at the end of "int i=0". The PDE window shows the compile error message of "unexpected token: int" and highlights the line of "int i=0". In this way, you can locate the place where it would contain errors and you can debug the errors.
In print debugging, you insert the printing method to show the status of variables you are using in the code and check if the status of them is what you intend. You can also check the control flow of the code by checking if the printing method you insert is actually executed printing the message.
Example of print debugging with IG.p() is shown below.
add_library('igeo') size( 480, 360, IG.GL ) i=10 print("initial value of i =" + str(i) ) i = 20 print("value of i at check point 1=" + str(i) ) i = i*2 print("value of i at check point 2=" + str(i) ) i = (i-i*2+3)/2 print("value of i at check point 3=" + str(i) )
Please note that when you concatenate multiple data including String value, you use + to concatenate.
The error messages above are prefixed with "sketch_tutorial.setup: " which is a name of class and a name of method where the print method is inserted. If you need you can suppress this prefix by putting IG.disablePrintPrefix() method in the beginning of the code. Showing this prefix is useful when you have multiple methods and classes.