Game Development Community

This.schedule... help

by Jason Cahill · in Torque Game Builder · 05/06/2006 (11:58 am) · 3 replies

I used to have this working in Alpha 1, but now it doesn't work anymore... I've been reading various threads to no avail. I'd love it if someone can point out the error in my ways.

Here is a trivial class and test function:

// declare my new class "CTest"
new ScriptClass(CTest);
 
// static TestObject factory
function CTest::create()
{
   %to = new ScriptObject(CTest);
   %to.m_valueA = 0;
   %to.m_valueB = 0;
   return %to;
}
 
function CTest::setValueA(%this, %value)
{
   %this.m_valueA = %value;
}
 
function CTest::setValueB(%this, %value)
{
   %this.m_valueB = %value;
}
 
function CTest::add(%this)
{
   return %this.m_valueA + %this.m_valueB;
}
 
function DoIt()
{
   %to = CTest::create();
   %to.setValueA(10);                     // m_valueA = 10;
   %to.setValueB(20);                     // m_valueB = 20;
   echo(%to.add());                       // echos "30" to the console
   
   %to.dump();                            // fails
   %to.schedule(1000, "setValueA", 100);  // fails
}

The dump and schedule commands return:

scripts/TestObject.cs (35): Unknown command dump.
  Object CTest(1138) CTest -> ScriptObject -> SimObject
scripts/TestObject.cs (35): Unknown command schedule.
  Object CTest(1138) CTest -> ScriptObject -> SimObject

What am I doing wrong?

#1
05/06/2006 (12:36 pm)
Jason,

This might be something that exists in TGB but not in TGE : I'm not sure there is a class called script Class.

AFAIK, your code should look like this :
// declare my new class "CTest"
new ScriptObject(CTest) 
{
     class = "CTest";
}

// static TestObject factory
function CTest::create()
{
   %to = new ScriptObject(:CTest); // see the colon before CTest
   %to.m_valueA = 0;
   %to.m_valueB = 0;
   return %to;
}
#2
05/06/2006 (1:18 pm)
That works! So, first off, thank you Bruno.

But, now there's a second order problem that doesn't seem to cause any harm. In my console output I get:

Error: cannot change namespace parent linkage for CTest from ScriptObject to CTest.

Questions:
(1) What does that mean?
(2) Should I care?
(3) How do I get rid of that?

Thanks!
#3
05/07/2006 (7:07 am)
I think it's basically because you have both an object and a class called "CTest" try changing :

// declare my new class "CTest"
new ScriptObject(CTestObject)

and
%to = new ScriptObject(:CTestObject); // see the colon before CTest