congrats...
Tips for debugging (use for my programming, and always use for
hacking games last time too):
Comment codes part by part... I call it divide and conquer... In
this way, you will know roughly which part of the code gives you
your error.
Within the error part, repeat the divide and conquer method... Do
it recursively till you arrive at maybe a small part of the code
which you can just read through easily...