-
Notifications
You must be signed in to change notification settings - Fork 3
Debugging
Besides throwing errors, using print statements, and unit testing your code, there are a few other methods of debugging. If you run wiimake with the option --save-temps, then all temporary files used to generate the code will be kept. The most important one is injected_code.txt. This contains all of the assembly code that was injected into the game. Now you can step through your code in Dolphin debug mode.
int global_array[100];
void _main() {...}
Forgetting to initialize non-static global variables can cause diabolical bugs. In the above example, the compiler does not treat global_array as if its size is 100 * sizeof(int). Because of this, wiimake still puts this variable at an address, but thinks it is only 4 bytes long. Any number of things could be adjacent in the executable, which means that something like global_array[50] = 10; could potentially overwrite lines of code or other variables in your code. This can be extraordinarily hard to debug, unless you realize this is the source of the mistake.
static global variables don't seem to have this problem, but as a precaution it is probably a good idea to initialize all of your variables.
Whenever a Logic struct that has been passed to the AI with addLogic is triggered, it clears the AI of all logic and moves. This can be easy to forget and is the source of many errors when using AI.
Related to the previous error, be careful when calling addMove directly from a Logic struct. This can create huge problems if the move that is called is Indefinite. An indefinite move called directly from logic will result in the top level loadDefaultLogic function being called while the controller is not in a neutral position. You could find a way to get around this problem, but it would not be good code design.
Functions called as FunctionCall should have parameters of type FunctionArg. However, due to the way parameters are passed they could also be 32-bit integers or pointers, but they cannot be floats. If your function has a signature like:
void foo(float x)
You will not be able to call it in a Logic struct.