by DST » Sun Feb 20, 2011 3:57 pm
Ge error checking is standard, as i would expect to find in any script parser. There are two things that are expected of the user, however, with most languages:
1. You understand the language to an extent that you can understand why it errs.
2. You don't cram too much junk into your lines.
The more junk you cram into one line, the more possible errors you can have there. It is better to declare variables, and set those first, then use them in the code, rather than doing your calculations inside function args.
moveto(player.x-view.x+100-enemy.x/2, 100); <----don't do complex math inside function calls.
int xx=player.x-view.x+100-(enemy.x/2) <----instead, do the math outside in a local variable.
moveto(xx, 100);
And that's just an example, there is much more to it, not just that we do the math outside the function, but that we do the math in segments so we can reuse portions of it. Ever see this?
this->x=x+(width/2); that->x=x+(width/2); <----a lot of possible errors in this line
instead,
int x2=x+(width/2); <----now the error will be specific to the line; you'll know what's wrong instantly.
this->x=x2;
that->x=x2;
This is not only for error checking, but also so you can handle and reuse variables. Sometimes you have to make changes, but the changes you make are nested deep inside a line of math inside a function call and hard to edit or error check or reuse. It's sloppy coding and it hurts you in the long run.
Just for fun, who here can tell me what 'Read Error in invalid memory Area" means? Once you understand what causes that error, it makes complete sense. The error is a perfect description of what's wrong.