Script made objects not appearing
by James Higgins · in Torque Game Builder · 08/24/2007 (6:02 pm) · 2 replies
I've made up something that, from what I understand, should be creating a few objects, but they never do.
function spawner::onLevelLoaded(%this, %scenegraph)
{
%this.block = new t2dStaticSprite()
{
scenegraph = SceneWindow2D.getScenegraph();
class = block;
blockCreator = %this;
setWorldLimit( clamp, getWords(%this.getWorldLimit(), 1, 4) );
setPosition(%this.getPosition());
setImageMap(redImageMap);
setSize(16, 16);
};
}
Can someone please tell me what I'm doing wrong? I have the classes typed in on the objects that should spawn them, I have the exec code for the script in the main file, etc.
Thanks
function spawner::onLevelLoaded(%this, %scenegraph)
{
%this.block = new t2dStaticSprite()
{
scenegraph = SceneWindow2D.getScenegraph();
class = block;
blockCreator = %this;
setWorldLimit( clamp, getWords(%this.getWorldLimit(), 1, 4) );
setPosition(%this.getPosition());
setImageMap(redImageMap);
setSize(16, 16);
};
}
Can someone please tell me what I'm doing wrong? I have the classes typed in on the objects that should spawn them, I have the exec code for the script in the main file, etc.
Thanks
#2
I thought I could pin it down, but I was wrong. For some reason, only the first block appears where it is supposed to, the others appear near the middle of the screen and flash. Thanks ahead of time for any help.
----
Fixed it, apparently it had something to do with setting the world limits.
08/24/2007 (7:24 pm)
Thank you very much, that fixed most of the problem.I thought I could pin it down, but I was wrong. For some reason, only the first block appears where it is supposed to, the others appear near the middle of the screen and flash. Thanks ahead of time for any help.
----
Fixed it, apparently it had something to do with setting the world limits.
Torque 3D Owner Stephen Zepp
Try the following:
function spawner::onLevelLoaded(%this, %scenegraph) { %this.block = new t2dStaticSprite() { scenegraph = %scenegraph; // ::onLevelLoaded provides the scenegraph as a param, so use it :) class = block; imageMap = redImageMap; }; %this.block.blockCreator = %this; %this.block.setWorldLimit( clamp, getWords(%this.getWorldLimit(), 1, 4) ); %this.block.setPosition(%this.getPosition() ); %this.setSize(16, 16); }Note: There may very well be another parameter or two that you should set to make sure the block is configured properly (collision comes to mind, for example), but the above code demonstrates what should be within the { }; portion of your new statement, and what shouldn't.