• entries
740
957
• views
732161

# Note to Self....

82 views

Just a quickie before I head off to bed. I managed to get some more time in coding Blitz Blox tonight, and I have to admit that these chain reaction are giving me a headache. They are a logistical nightmare I'm still working to unravel. Still, I'm having eureka moments every now and then.

Anyways I wanted to post about to things related to TorqueScript. The first is that I made the mistake once again of defining a 'new' object inside of another 'new' definition. I dunno why TS doesn't like this, but it doesn't. I thought I'd be safe because unlike last time, I wasn't doing two 'new' definitions on the same line. However I suppose as far as the compiler is concerned, this is one line:
%newReaction = new ScriptObject(){   id          = %this.chainReactionId++;   effectsNum  = 1;   effect0 = new t2dParticleEffect() { config = "chainReactionLink"; };};

This caused me some grief to track down because 'id' and 'effectsNum' would be assigned an empty string value instead of the integers I thought they contained.

The second thing that tripped me up bad was the fact that, for some reason Torque likes to add a trailing space to its object IDs. For example, if you were to do this:
%object = new t2dStaticSprite();echo("'" @ %object @ "'");

the output would look like this (obviously the ID number would vary):
'78977 '

What's important to note here is that blasted trailing space. Why? WHY I say! This caused my Schedule manager to throw up a parse error when I tried doing this:
Schedule.addFunction(false, %this, 250, "chainReaction", %dstBlock SPC %newReaction.id);

Since that last argument would be passed along as "65383 1" (note the extra space) when the Schedule manager pieces together the function call to chainReaction it comes up with "65383, ,1" for the parameters to pass. chainReaction only has two arguments, hence a parse error.

Bah. In case you weren't aware of that stupid trailing space, now you know. And if anyone could tell me why it's there, I would appreciate it.

Okay I'm done. In between coding and doing some GDNet GDC prepwork, I played some GH II and beat Hard with all 5 stars and got a few more 5 star ratings on Expert as well. It works out nice, getting up to play a song every once in a while, keeps me from being chair-bound for a lengthy period of time.

The End

I admit I don't know any TorqueScript, but isn't the following not more "correct"?

%newReaction = new ScriptObject()
{
id          = %this.chainReactionId++;
effectsNum  = 1;
%this.effect0 = new t2dParticleEffect() { config = "chainReactionLink"; };
};


I've replaced the %newReaction.effect0 with %this.effect0, since %newReaction won't exist until the first new is finnished.

Or possibly this is even more correct:
%newReaction = new ScriptObject()
{
id          = %this.chainReactionId++;
effectsNum  = 1;
effect0 = new t2dParticleEffect() { config = "chainReactionLink"; };
};


But as I said, I don't know any TorqueScript.

Curse my sleep-deprived mind! You are correct! I totally screwed up that example. It was indeed supposed to be
%newReaction = new ScriptObject()
{
id          = %this.chainReactionId++;
effectsNum  = 1;
effect0 = new t2dParticleEffect() { config = "chainReactionLink"; };
};


The reason it's how it is above is because I copy-pasted the proper code, which was
%newReaction = new ScriptObject()
{
id          = %this.chainReactionId++;
effectsNum  = 1;
};
%newReaction.effect0 = new t2dParticleEffect() { config = "chainReactionLink"; };


So I forgot to delete "%newReaction." when I used that to make my example

Gah I'm sure someone's already pointed it out over at my GG journal as well. Good eyes my friend, good eyes.

*edits journal post

## Create an account

Register a new account