Game Development Community

Empty %this

by Samuel Marcus · in Torque Game Builder · 11/09/2006 (11:37 pm) · 5 replies

I have a class which can't access %this for some reason... any references to %this come up empty, even a direct call for %this.safeDelete()... other objects can refer to it (for instance, to call the function with the safeDelete in it... I know it gets called because there's an echo after the delete command). Ideas...?

(sorry if this is a common question)

#1
11/10/2006 (8:10 am)
You most likely forgot to include it in the argument list. %this gets automatically passed when you call a method on an object with the dot operator, but if you don't declare it, it'll just ignore it.

Your method should look like this:
function MyClass::DoSomething(%this)
{
   %this.DoSomethingElse();
}

and I'm guessing it looks like this:
function MyClass::DoSomething()
{
   %this.DoSomethingElse();   // fails because you forgot to include %this in the argument list
}
#2
11/10/2006 (11:18 am)
Ok, I will try that... I had been figuring the %this was implicit (I suppose it half is).
#3
11/10/2006 (11:37 am)
Ok, adding a swath of %this's to my arguments seems to have fixed some callback problems I was having, but I still can't call safeDelete.

(11): Unknown command safeDelete.
Object (2548) weather -> ScriptObject -> SimObject

This is how I set up the object:

%WeatherGod = new ScriptObject()
	{
		class = weather;
		sceneGraph = $scene;
	};
	%WeatherGod.initializeWeather();
	%WeatherGod.addCloud($scene);

($scene is scenegraph... is there a better way to access this from game.cs than pulling the scenegraph from the sceneWindow2d?)

then when I call (later on)
function weather::cloudRemoved(%this)
{
	%this.addCloud(%this.scenegraph);
	%this.safeDelete();
}
A cloud gets added and I get that unknown command error. Is it because I am using ScriptObject?
#4
11/10/2006 (11:40 am)
ScriptObject doesn't have safeDelete()... it only has delete() :)
#5
11/10/2006 (11:45 am)
You sir, are a poet and a scholar.