Tutorials | (back to the list of tutorials) |
import processing.opengl.*; import igeo.*; size( 480, 360, IG.GL ); int i=0
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.
import processing.opengl.*; import igeo.*; size( 480, 360, IG.GL ); int i=10; IG.p("initial value of i =" + i ); i = 20; IG.p("value of i at check point 1=" + i ); i = i*2; IG.p("value of i at check point 2=" + i ); i = (i-i*2+3)/2; IG.p("value of i at check point 3=" + 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.