by date
Some TorqueScript no-no's
Some TorqueScript no-no's
| Name: | Drew -Gaiiden- Sikora | ![]() |
|---|---|---|
| Date Posted: | Mar 03, 2007 | |
| Rating: | 2.0 out of 5 | |
| Public: | YES | |
| Comments: | YES | |
| RSS Feed: | or Subscribe with . | |
| Profile Page: | View profile page for Drew -Gaiiden- Sikora |
Blog post
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:
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:
the output would look like this (obviously the ID number would vary):
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:
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
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
Recent Blog Posts
| List: | 12/03/08 - GDNet: Weekly Sitrep 12/03/08 - GDNet: Tales from Journal Land 11/27/08 - GDNet: Weekly Sitrep 11/21/08 - GDNet: Tales from Journal Land 11/17/08 - GDNet: Tales from Journal Land 11/07/08 - GDNet: Tales from Journal Land 11/06/08 - GDNet: Weekly Sitrep 10/31/08 - GDNet: Tales from Journal Land |
|---|
Submit your own resources!| Simon Love (Mar 03, 2007 at 16:29 GMT) |
First, When you try to define your %newReaction.effect0, you are still in %newreaction's definition, so maybe changing %newReaction.effect0 to simply effect0 would work. After all, to access the id variable, you would write %newreaction.id to access its value, outside of this initial definition. Same for effect0. In the definition, effect0, outside of it, %newreaction.effect0.
For the trailing space problem, I wasn't aware of this, as I always use %object.getid(), which consistently works. try using getid() to make sure, but I agree with you that there is no logical explanation why there would be a trailing space there.
Hope that helped a bit.
| David Higgins (Mar 03, 2007 at 17:43 GMT) |
function reaction::onAdd(%this)
{
for(%x = 0; %x < %this.effectsNum; %x++)
{
%this.effect @ %x = new t2dParticleEffect() { config = %this.effect @ %x; };
}
}
%newReaction = new ScriptObject()
{
id = %this.chainReactionId++;
superClass = "reaction";
effectsNum = 1;
%newReaction.effect0 = "chainReactionLink";
};
That code would allow for N effects, using your already existant effectsNum field, and then you can use different particle datablocks by assigning them to the effectN value, you could also, for the sake of simpler code, set a default so that if the value does not exist, you simply default to "chainReactionLink", allowing for this:
function reaction::onAdd(%this)
{
for(%x = 0; %x < %this.effectsNum; %x++)
{
%v = %this.effect @ %x;
if(%v $= "") %v = "chainReactionLink";
%this.effect @ %x = new t2dParticleEffect() { config = %v; };
}
}
%newReaction = new ScriptObject()
{
id = %this.chainReactionId++;
superClass = "reaction";
effectsNum = 3;
};
Note the lack of existance for effect0, effect1 and effect2 ... however, in the onAdd, they will be created and given the value of %c ("chainReactionLink")
Pretty sure that code works "as is", but might need some TLC
| Drew -Gaiiden- Sikora (Mar 04, 2007 at 06:07 GMT) |
Quote:
First, When you try to define your %newReaction.effect0, you are still in %newreaction's definition, so maybe changing %newReaction.effect0 to simply effect0 would work. After all, to access the id variable, you would write %newreaction.id to access its value, outside of this initial definition. Same for effect0. In the definition, effect0, outside of it, %newreaction.effect0.
@Simon - Yes *sigh* this was pointed out to me as well on my GDnet journal. Check out my comment response at the bottom for my explanation
*edits journal entry
@David - thx for the reminder of using onAdd. I guess I just have to get into the habit of using it. I always forget about it
@both - .getId(), check! :)
| Ben R Vesco (Mar 04, 2007 at 09:24 GMT) Resource Rating: 1 |
When you write
%dstBlock SPC %newReaction.id
you are TELLING torque to add a space between the object id and the reaction id. SPC is a string concatenation operator that adds a space between the two strings you are combining. I have never had a problem or seen any trailing spaces.
In fact, I even popped open a console and tried
$obj = new t2dStaticSprite();
echo("'" @ $obj @ "'"); // printed '2883'
echo("'" @ $obj.getId() @ "'"); // printed '2883'
To summarize, TorqueScript does not add a trailing space to your object ids whether you access them directly or through getId()
You must be a member and be logged in to either append comments or rate this resource.



2.0 out of 5


