Dealing with undeclared variables and vague compile errors
by Ian Poma · in Torque Game Builder · 06/26/2006 (7:19 pm) · 9 replies
I have gotten over my growing pains with TGB and feel I am getting the hang of the product. As I am moving beyond just coding quick tests and simple demos, I keep getting pinched by a few limitations with the compiler.
1) You don't have to declare any variables, and there is no option to make the compiler generate a warning if you are using a variable that hasn't been assigned. This causes serious problems when you swap a % sign for a $ sign, or a have a typo in a variable name. The only way to really detect these errors is to comb through your code line by line and double/triple check everything.
2) When you have a syntax error, the compiler doesn't provide any useful information regarding the error, nor does it correctly identify the right line. For example:
Now, there error above is just a missing semicolon at the end of the line. But the compiler didn't provide a useful message, and the line that was in error is 2 lines above the pound signs.
Problems like these are fairly trivial when you coding short demos, but as your code grows into hundreds of lines and beyond, they will bring you to a halt.
Obviously there are people out there working on larger projects, and completed games have already been shipped with TGB. So my question is, how have you delt with these two issues?
1) You don't have to declare any variables, and there is no option to make the compiler generate a warning if you are using a variable that hasn't been assigned. This causes serious problems when you swap a % sign for a $ sign, or a have a typo in a variable name. The only way to really detect these errors is to comb through your code line by line and double/triple check everything.
2) When you have a syntax error, the compiler doesn't provide any useful information regarding the error, nor does it correctly identify the right line. For example:
/gameScripts/actionMap.cs Line: 6 - parse error
>>> Advanced script error report. Line 6.
>>> Some error context, with ## on sides of error halt:
function LoadPlayerActionMap()
{
echo("-- calling LoadPlayerActionMap");
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();")
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
## ## moveMap.bindCmd(keyboard, "space", "playerJump();", "");
} Now, there error above is just a missing semicolon at the end of the line. But the compiler didn't provide a useful message, and the line that was in error is 2 lines above the pound signs.
Problems like these are fairly trivial when you coding short demos, but as your code grows into hundreds of lines and beyond, they will bring you to a halt.
Obviously there are people out there working on larger projects, and completed games have already been shipped with TGB. So my question is, how have you delt with these two issues?
#2
Usually a good IDE will alert you to such problems. Trouble is, TS doesn't have an IDE that covers all the bases a good IDE should. There is Torsion, which is the IDE that seems most popular here, but it doesn't provide that kind of feedback on your code. Then there is Codeweaver which does provide that kind of feedback, but lacks some of the features that make Torsion so nice. The best thing I can say is to just know that you will get used to seeing those kinds of errors and instantly think, missing semicolon, unclosed string literal, local var not initialized, etc. and get better at tracking those things down.
06/26/2006 (10:50 pm)
Experienced programmers are just used to those things. "Oh I must've missed a semicolon" is probably permanently ingrained in the brain of every programmer on the planet. You'll get used to it.Usually a good IDE will alert you to such problems. Trouble is, TS doesn't have an IDE that covers all the bases a good IDE should. There is Torsion, which is the IDE that seems most popular here, but it doesn't provide that kind of feedback on your code. Then there is Codeweaver which does provide that kind of feedback, but lacks some of the features that make Torsion so nice. The best thing I can say is to just know that you will get used to seeing those kinds of errors and instantly think, missing semicolon, unclosed string literal, local var not initialized, etc. and get better at tracking those things down.
#3
I've been making my living as a developer for almost 10 years now, and I can't remember the last time I used a compiler of any type that didn't offer up some type of error message, no matter how obtuse.
Getting better at manually inspecting my code isn't a viable solution to either of my concerns, but thank you both for answering.
06/26/2006 (11:36 pm)
Wow, was there a turnip truck around here when I made my initial post, because I most certainly didn't just fall off one.Quote:
The second issue you describe is a common one in any compiler, not just TorqueScript--compilers in general have to be able to decode what you are attempting to the best of their ability, but incorrect scoping, blocking, and misalgined/unaligned quotes confuse the compilers even more than the humans.
I've been making my living as a developer for almost 10 years now, and I can't remember the last time I used a compiler of any type that didn't offer up some type of error message, no matter how obtuse.
Getting better at manually inspecting my code isn't a viable solution to either of my concerns, but thank you both for answering.
#4
As Ben mentioned, there are TorqueScript IDE's available, both Torsion and CodeWeaver. Check one or both out and see if it meets your needs.
Oh, and I've been using compilers in either a professional (10+ years), or personal (19 years) manner, and I've yet to find one that can pinpoint exactly where problems of this nature exist as part of the compilation. Yes, the IDE's allow you to trace them much easier than raw visual inspection in many cases, but until the recent release of MS Visual Studio Express as free, I've yet to see one come out that didn't cost more than Torque and were strong enough to rely on absolutely.
If you think Torquescript's byte code compiler is rough, you should try using TCL--a much more mature scripting language, and one that is used professionally in dozens of industries--and it doesn't even always tell you what file the problem is in, much less what character position exactly.
Not to be rude, but if you want to be treated with a specific level of experience/background, let us know that background in your questions so we can target an answer at your level.
06/27/2006 (7:04 am)
@Ian: Given that your profile states you are a "Gamer--Novice", and provides exactly zero other information, how were we to know in any way that "you didn't just fall off the turnip truck"? We don't get to peek inside your head to see your background without some information from you giving us a good frame of reference to phrase a response.As Ben mentioned, there are TorqueScript IDE's available, both Torsion and CodeWeaver. Check one or both out and see if it meets your needs.
Oh, and I've been using compilers in either a professional (10+ years), or personal (19 years) manner, and I've yet to find one that can pinpoint exactly where problems of this nature exist as part of the compilation. Yes, the IDE's allow you to trace them much easier than raw visual inspection in many cases, but until the recent release of MS Visual Studio Express as free, I've yet to see one come out that didn't cost more than Torque and were strong enough to rely on absolutely.
If you think Torquescript's byte code compiler is rough, you should try using TCL--a much more mature scripting language, and one that is used professionally in dozens of industries--and it doesn't even always tell you what file the problem is in, much less what character position exactly.
Not to be rude, but if you want to be treated with a specific level of experience/background, let us know that background in your questions so we can target an answer at your level.
#5
Anyhow, my object wasn't to get into a pissing match about how torque script compares to other languages and what features it does or does not have. I figured the problems I was having would be common, and given that fact that Torquescript has been used for years in the torque engine - it would be a solved problem.
Given the answers give thus far, I just need to stare at my code longer until it makes sense, and thats all the information I need.
06/27/2006 (8:21 am)
I am not really looking for an answer that is targeted to my background or my experience level. I am looking for a straight answer. When I say that the compiler isn't providing any error message beyond a generic response, and you tell me that is a common problem with any compiler, I am going to call baloney.Anyhow, my object wasn't to get into a pissing match about how torque script compares to other languages and what features it does or does not have. I figured the problems I was having would be common, and given that fact that Torquescript has been used for years in the torque engine - it would be a solved problem.
Given the answers give thus far, I just need to stare at my code longer until it makes sense, and thats all the information I need.
#6
BTW Stephen did you find that pref? If not is it in Maurina's book or should I search the site?
06/27/2006 (9:31 am)
Most compilers do not give a good message when you have missing semi colons or brackets. It's just the way it is and you need to look for those things when a compiler comes back with cryptic messages.BTW Stephen did you find that pref? If not is it in Maurina's book or should I search the site?
#7
06/27/2006 (12:07 pm)
$Con::warnUndefinedVariables = True;
#8
06/27/2006 (12:45 pm)
Thanks a bunch Labrat!
#9
HTH
06/28/2006 (6:17 pm)
In addition to using $Con::warnUndefinedVariables, I modified the SimObject method getDataField() (in simBase.cc). By default, getDataField() just returns an empty string when it can't find a field. I now have it print out a warning message containing the field it can't find before it returns the empty string (goto's have their uses :) )HTH
Torque 3D Owner Stephen Zepp
The second issue you describe is a common one in any compiler, not just TorqueScript--compilers in general have to be able to decode what you are attempting to the best of their ability, but incorrect scoping, blocking, and misalgined/unaligned quotes confuse the compilers even more than the humans.
Your best option is to get used to recognizing the symptoms--for example, when you see a reported error in a line that pretty obviously doesn't have any errors, it's guaranteed the error is above. First thing I do is to look for unmatched {}, (), and/or a missing ;.