Game Development Community

ScriptObject

by Ron Yacketta · in Torque Game Engine · 06/05/2003 (7:06 am) · 10 replies

Folks,

Been looking into using ScriptObject for a few things. One thing I noticed is that no matter how I slice/dice it I am unable to make a function based from the ScriptObject

IE:

$JUNK = new ScriptObject(MyScriptObject)
{
  blah="blah";
};

function MyScriptObject::SayHello()
{
 echo("HA! gotcha ScriptObject);
}

when MyScriptObject::SayHello is used (either directly or via $JUNK.SayHello() or $JUNK::SayHello()) I get the following

Unknown command SayHello.
  Object MyScriptObject(1438) ScriptObject -> SimObject

So, my questions is. WTF am I doing wrong ;) could have sworn the above was possible.

-Ron

#1
06/05/2003 (7:15 am)
Try putting a class to it... Code should be something along the lines of:

$newScriptObject = new ScriptObject(ScriptObjectName)
{
  class   = ScriptObjectClass;
  data    = "Wiggy wiggy wa wiggy wa wiggy wiggy wa";
};
 
 
function ScriptObjectClass::DoSomething(%this)
{
  echo("My data = " @ %this.data);
}

Should be able to be called using:

ScriptObjectName.DoSomething();

or ...

$newScriptObject.DoSomething();


Edit: Stupid formatting.
#2
06/05/2003 (7:17 am)
From the torque tutorial: http://www.garagegames.com/docs/torque.sdk/coding/console.html#overview

new ScriptObject(MyObject) {
class = Bar;
superClass = Foo;
};

function Bar::doSomething(%this)
{
echo("Hi!");
}


you need to use the class = 'youclass' to manage your functions instead of ScriptObject('MyScriptObject').
#3
06/05/2003 (7:35 am)
The scriptObject code is not linking the scriptObject name into the nameSpace.

For now you'll have to use:

$JUNK = new ScriptObject(MyScriptObject)
{  
     class="MyScriptObjectClass";
     blah="blah";
};

function MyScriptObjectClass::SayHello()
{ 
     echo("HA! gotcha ScriptObject");
}
#4
06/05/2003 (7:36 am)
Yeah yeah yeah ;) I should have know this. Man I feel really stupid now *sigh* especially knowing that I wrote a darn doc on the scripting engine *sigh*
#5
06/05/2003 (7:53 am)
To fix this behaviour you can replace your scriptObject.cc file with the following:

//-----------------------------------------------------------------------------
// Torque Game Engine 
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

#include "platform/platform.h"
#include "console/simBase.h"
#include "console/consoleTypes.h"

class ScriptObject : public SimObject
{
   typedef SimObject Parent;
   StringTableEntry mClassName;
   StringTableEntry mSuperClassName;
public:
   ScriptObject();
   bool onAdd();
   void onRemove();
   
   DECLARE_CONOBJECT(ScriptObject);
   
   static void initPersistFields();
};

IMPLEMENT_CONOBJECT(ScriptObject);

void ScriptObject::initPersistFields()
{
   addGroup("Classes");	// MM: Added Group.
   addField("class", TypeString, Offset(mClassName, ScriptObject));
   addField("superClass", TypeString, Offset(mSuperClassName, ScriptObject));
   endGroup("Classes");
}

ScriptObject::ScriptObject()
{
   mClassName = "";
   mSuperClassName = "";
}

bool ScriptObject::onAdd()
{
   if(!Parent::onAdd())
      return false;
   const char *name = getName();      // Added by LabRat
   if(mClassName[0])
   {
      if(mSuperClassName[0])
      {	
// Added by LabRat
// Reason: Links the ScriptObject name into the namespace so scriptObjects will follow
//         the standard that all other objects in Torque follow.
       	
      	 if(name && name[0])
      	 {
      	 	Con::linkNamespaces(mClassName, name);
      	 }
// End
         Con::linkNamespaces(mSuperClassName, mClassName);
         Con::linkNamespaces("ScriptObject", mSuperClassName);
      }
      else
      {
// Added by LabRat      	
      	 if(name && name[0])
      	 {
      	 	Con::linkNamespaces(mClassName, name);
      	 }
// End
         Con::linkNamespaces("ScriptObject", mClassName);
      }
        
         
      mNameSpace = Con::lookupNamespace(name);	// Changed mClassName to name - LabRat
   }
// Added by LabRat      
   else
   {
  	 if(name && name[0])
      	 {
      	 	Con::linkNamespaces("ScriptObject", name);
      	 }
         
      mNameSpace = Con::lookupNamespace(name);
   }
// End   
   return true;
}

void ScriptObject::onRemove()
{
   Parent::onRemove();
}
#6
06/05/2003 (8:20 am)
Am I slow or what? I was going to-do the same exact thing once I did some touch up to my scripts.
#7
06/14/2003 (9:29 pm)
I have a slightly more compact version of the patch... Soon as I get it tested I'll post it up here, then I'll run it by Mark and see what he thinks.
#8
11/06/2005 (12:42 am)
Hey whatever happened with that Ben? It's been quite awhile since anything was mentioned.
#9
11/06/2005 (1:21 am)
Well, I worked on Atlas, and did Torque Technologies stuff, and... most of my R&D into console stuff that's applicable has been merged into 1.4. No far-ranging script changes like enabling that are going to happen to stock Torque in the foreseeable future, but you never know.
#10
11/06/2005 (1:37 am)
Ok, just curious if this was something that was going into 1.4 or something. As an aside, is there a listing of what will be different from 1.3 to 1.4 somewhere? I can't seem to find one anywhere.