Unknown command delete ?
by Arsen Gnatkivskyi · in Torque Game Builder · 10/04/2007 (3:32 am) · 8 replies
Hi All !
Perhaps I do not know someshing about ScriptObject, so tell me please:
And what I have in console :
So why TGB dont seen ScriptObject methods ?
By the way it heppens only in first run after start tgb. At second run all works fine.
Please help !
Perhaps I do not know someshing about ScriptObject, so tell me please:
function startGame(%level)
{
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
echo("----------------------------------");
$buba2 = buba2::create();
if (!isObject($buba2))
{
echo("==========================error");
}
($buba2).dump(); /// HERE IS ERROR !!!
$buba2.delete(); /// HERE IS ERROR !!!
echo("----------------------------------");
//--------------
moveMap.push();
if( isFile( %level ) || isFile( %level @ ".dso"))
sceneWindow2D.loadLevel(%level);
}
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
}
function buba2::create()
{
return new ScriptObject()
{
class = buba2;
xz = "xz2";
};
}
function buba2::onRemove(%this)
{
echo("REMOVE!!!!!!");
}And what I have in console :
---------------------------------- testCreate/gameScripts/game.cs (37): Unknown command dump. Object (2430) buba2 -> ScriptObject -> SimObject testCreate/gameScripts/game.cs (38): Unknown command delete. Object (2430) buba2 -> ScriptObject -> SimObject ----------------------------------
So why TGB dont seen ScriptObject methods ?
By the way it heppens only in first run after start tgb. At second run all works fine.
Please help !
#2
10/04/2007 (4:17 am)
I renamed buba2::create() to buba2::Buba2_Create(). The same result :(
#3
Here:
10/04/2007 (1:37 pm)
Change the ::create function to first create and store the new ScriptObject.. and then return the stored object.. Ie put it in a variable first.Here:
function buba2::create()
{
%newObject = new ScriptObject()
{
class = buba2;
xz = "xz2";
};
return %newObject;
}
#4
10/05/2007 (3:13 am)
No, nothing changed :( all the samefunction startGame(%level)
{
// Set The GUI.
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
//--------------
echo("----------------------------------");
$buba2 = buba2::_create();
if (!isObject($buba2))
{
echo("==========================error");
}
($buba2).dump();
$buba2.delete();
echo("----------------------------------");
//--------------
moveMap.push();
if( isFile( %level ) || isFile( %level @ ".dso"))
sceneWindow2D.loadLevel(%level);
}
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
}
function buba2::_create()
{
%newObject = new ScriptObject()
{
class = buba2;
xz = "xz2";
};
return %newObject;
}
function buba2::onRemove(%this)
{
echo("REMOVE!!!!!!");
}
#5
I think you misunderstood my original post, I meant name the full function
and then change your call to it to
Note the :: has been removed completely.
10/05/2007 (3:59 am)
Quote:function buba2::_create()
I think you misunderstood my original post, I meant name the full function
function buba2_create()
and then change your call to it to
$buba2 = buba2_create();
if (!isObject($buba2))
{
echo("==========================error");
}Note the :: has been removed completely.
#6
But it is not looks very pretty... Why it happens ? Why I cant delete object created in buba2::_create() ?
10/05/2007 (4:55 am)
Yes, it works fine ! Thanks !But it is not looks very pretty... Why it happens ? Why I cant delete object created in buba2::_create() ?
#7
Whereas by having the create function not a part of buba2, the first time the buba2 namesspace gets used is on a ScriptObject that has the buba2 class, thus putting the buba2 namespace under the ScriptObject namespace.
I may be wrong on this, but it seems consistent with the way things work. For the same reason, you can't use the same script class with different base classses (for instance, having a t2dStaticSprite PlayerMissile and then a t2dAnimatedSprite PlayerMissile).
For a solution that might not look so bad, you could try calling the function create::buba2, or CBuba2::create; pretty much anything that isn't going to be used as a class name.
10/05/2007 (1:35 pm)
I believe what happens is that Torque's automatic namespace binding is triggering. When you call buba2::create without ever having created a buba2 object, the buba2 namespace is put under the "non-object" namespace, with the result that you can't call any object functions on it.Whereas by having the create function not a part of buba2, the first time the buba2 namesspace gets used is on a ScriptObject that has the buba2 class, thus putting the buba2 namespace under the ScriptObject namespace.
I may be wrong on this, but it seems consistent with the way things work. For the same reason, you can't use the same script class with different base classses (for instance, having a t2dStaticSprite PlayerMissile and then a t2dAnimatedSprite PlayerMissile).
For a solution that might not look so bad, you could try calling the function create::buba2, or CBuba2::create; pretty much anything that isn't going to be used as a class name.
#8
10/06/2007 (1:50 am)
Thanks for explanation!
Torque Owner Gary Preston
If you rename your create method to Buba2_Create() then dump and delete should work fine. You can also try Buba2::CreateObject() or any other name than just "Create".