Game Development Community

Rainy Day Tutorial operand order syntax error

by Matt Senne · in Torque Game Builder · 09/06/2008 (9:45 am) · 3 replies

First off, if I'm posting this in the wrong place tell me that and I'll deal with that first and foremost (I'm new here and the search feature for the forums is limited).

I am using Torque Game Builder 1.7.4 on Mac OS X 10.5.4.

Using the code provided in the official online documentation for the Rainy Day Tutorial I have entered this code into a PlantGrowthBehavior.cs

function PlantGrowthBehavior::runAnimation(%this, %direction)
{
if (%direction < 0.0)
{
if (%this.owner.getAnimation() != %this.growAnim)
{
%frame = (getWordCount(%this.growAnim.AnimationFrames) - 1) - %this.owner.getAnimationFrame();
%this.owner.PlayAnimation(%this.growAnim);
%this.owner.setAnimationFrame(%frame);
}
} else
{
if (%this.owner.getAnimation() != %this.dieAnim)
{
%frame = (getWordCount(%this.dieAnim.AnimationFrames) - 1) - %this.owner.getAnimationFrame();
%this.owner.PlayAnimation(%this.dieAnim);
%this.owner.setAnimationFrame(%frame);
}
}
}

When running this code there were several consequences:
-the plants never grow (they just die and stay dead)
-the PlantGrowthBehavior.cs.dso was NOT generated
-hitting tilde (~) while running the app to view the error console I could see a " syntax error " on line 46 of my file, which was the line after this:

if (%this.owner.getAnimation() != %this.growAnim)

By trial and error I was able to determine that the syntax error was due to the operands to the != operator being in the wrong order. In other words, to fix I changed the above line to

if (%this.growAnim != %this.owner.getAnimation())

Likewise,
if (%this.owner.getAnimation() != %this.dieAnim)
was changed to
if (%this.dieAnim != %this.owner.getAnimation())

I can't find any reference of anyone else having this problem but for me it is repeatable. After making the changes above the tutorial works as it is supposed to.

I have some questions in closing:
-should I have posted this bug in a different forum? (honestly, I tried to find a better place)
-has this already been reported somewhere that I could have noticed it? I'd love to know for future reference.
-is this operand order a feature or bug? Can anyone speculate on why function calls cannot be the left operand?

About the author

Recent Threads


#1
09/06/2008 (10:47 am)
@Matt - Interesting. I'll have to give this a shot later on in the day. After I finish testing the tutorial, I'll post another message here.

To answer your other questions:

1. You posted in a TGB forum, so that's good enough. If you want to get very specific, you can post tutorial and doc related issue in the Official TGB Documenation Feedback Thread.

2. I haven't heard of that being posted previously, but that tutorial was written before I started working at GG.

3. I've not heard of this before, in any script, so I'll have to dig a little to see if there are previous examples of this issue.
#2
09/09/2008 (2:36 pm)
@Matt - I just finished the Rainy Day Tutorial, starting from scratch. I went step by step, had no errors, and was unable to replicate your error.

However, I should have noticed sooner that you mentioned you had a syntax error on line 46. There is a good chance that you introduced a bad symbol or line. Were you copying and pasting the sample code? Did you debug through the line?

Overall, the tutorial seems fine with no other issues.
#3
09/09/2008 (2:52 pm)
Regarding the syntax error: I copy pasted the code a chunk at a time, and manually reindented it as I read through it all. Tabbing the lines looked nice in my editor, but put odd symbols in the debug console when echoing the lines of code so I re-copy/pasted the code and left the space indents as-is. Same error.

I did not debug through because I'm running OS X and therefore can't use Torsion or CodeWeaver. I'm just saving text files in TextWrangler and dropping them in the directory.

What confuses me about this issue is that I was able to avoid it by reordering the innermost code - not by retyping it or changing the indentations or any of the surrounding lines (I tried that, none of it worked). I tried editing lines below and above the error in question and it truly appeared that the 45th line was the problem and (as is typical) the error was reported on the following line. The parenthesis around the code that was changed were not modified so it seems unlikely that anything but the code I changed mattered for this.

I'll look into the text editor situation and see if there was a file format problem (ASCII instead of UTF8, or Unicode or some random bs that shouldn't matter and never does but did for me). My situation appears to be atypical (what idiot would do scripting without a debugger anyway?) so I'm not too worried about it. If I isolate the cause I'll post it here. Otherwise the workaround is simple so nobody should be too put out about it.

Thanks Michael!