Game Development Community

Torque Script Changes

by Patrick Shaw · in Torque 3D Professional · 05/12/2009 (3:28 am) · 9 replies

Going through the FPS starter kit, I've noticed some changes to TS (or possibly features that I never knew about). For example, StartUp.Gui line 146 has the following:

if (isObject(%this->StartupLogoSecondary))

I'm a designer, not a programmer, so I'm guessing that the "->" is a dynamic cast. Is this correct? Looking at other scripts, its obviously not required. Are the new TS features summarized somewhere yet? Is there a roadmap for the future of TS?

#1
05/12/2009 (3:56 am)
I've seen some compilers use . and -> for accessing class variables. Maybe this is another. I like . better because pointer symbols make me cry.
#2
05/12/2009 (4:22 am)
I think "->" is a shortcut for findObjectByInternalName. I could be wrong though.
#3
05/12/2009 (5:17 am)
Phillip appears right, taking a look inside of compiledEval,

case OP_SETCUROBJECT_INTERNAL:
            ++ip; // To skip the recurse flag if the object wasn't found
            if(curObject)
            {
               SimSet *set = dynamic_cast<SimSet *>(curObject);
               if(set)
               {
                  StringTableEntry intName = StringTable->insert(STR.getStringValue());
                  bool recurse = code[ip-1];
                  SimObject *obj = set->findObjectByInternalName(intName, recurse);
                  intStack[UINT+1] = obj ? obj->getId() : 0;
                  UINT++;
               }
               else
               {
                  Con::errorf(ConsoleLogEntry::Script, "%s: Attempt to use -> on non-set %s of class %s.", getFileLine(ip-2), curObject->getName(), curObject->getClassName());
                  intStack[UINT] = 0;
               }
            }
            break;

So -> is really just an alias to findObjectByInternalName... what's weird is that I think "-->" = "->" as well.
#4
05/12/2009 (6:05 am)
It is a pointer in C++
In C# for instance this would translate to
if (isObject(this.StartupLogoSecondary))

Where ase "this" is the current object, StartupLogoSecondary is a method of that object. so as you read through that code you see other pointers to methods like curObject->getName, where as curObject is defined earlier as a variable of type object, what ever that object might be, then that defined object has a method presumablely from a base class called getName() and getClassName()

But don't get to confused about pointers, there are different types, for instance

Fruit *Apple
Defines an Apple as a Fruit from the fruit class and makes a pointer to it.

**Apple is a pointer to a pointer of the Apple we created, usually generated and used elsewhere to pass elements around. Try not to get yourself confused to much in the C++ code side of the house.

It appears in these earely beta's, they are doing strict translation so they have less parsing to do in TS this time around, just take it straight as is from TS to C++ with as few traslations as possible.
#5
05/12/2009 (6:08 am)
Uhm, he's talking about TorqueScript, not C++ or C#. The TS interpreter apparently uses '->' as a shortcut for 'findObjectByInternalName' which IMO is pretty confusing coming from other script and programming languages...
#6
05/12/2009 (7:05 am)
Isn't that just the same thing? In C++ '->' returns a pointer to a method or variable, and looking at 'findObjectByInternalName' in that block of code posted by Tim it appears to be returning a pointer to the object passed into 'findObjectByInternalName.' If 'findObjectByInternalName' does as I suspect then it makes perfect sense to replace it with the shortcut '->' since its a lot easier to type and follows more closely with C and C++ syntax which torquescript is based upon.
#7
05/12/2009 (7:08 am)
In C++ '->' is a dereferencing operator used on pointers as an easier way to use the object pointed to (instead of writing (*ptr).function you write ptr->function). Haven't checked that 'findObjectByInternalName' function myself, so it might make sense to have it access by the '->' shortcut in TS.
#8
05/12/2009 (9:07 am)
Quote:
Its just syntactic sugar for findObjectByInternalName()...
It was first noticed a few months ago when it was also found within TGEa.
#9
05/12/2009 (10:20 am)
Its a feature that has always existed unless I'm wrong
I think it was also discovered in TGB during the EA phase if I remember right as the TGE / TGB editors use this in different places.

Its thought right that it is one of a handfull scripting features nowhere documented actually