Crash when using datablocks
by MrSpaceGame · in Torque Game Builder · 04/05/2012 (6:03 pm) · 1 replies
Hi Guys.
I have really throughly searched the net and could not find any solution for this so I ask for help here.
I hope someone can shed some light for me. As a sidenote, I WILL buy Torgue2D soon once I get my next paycheck.
Anyway, I have this datablock in datablocks.cs:
This is an exact reproduction of an object that I have in my level. So far, I just used clone() to get as many enemies as I need. It is a r-type style shooter, so I need a variable amount of enemies. Since clone() spams my log, I decided to use datablocks, since it is also more flexible.
However, once spawning begins, my game freezes and crashes:
Thanks for reading :).
I have really throughly searched the net and could not find any solution for this so I ask for help here.
I hope someone can shed some light for me. As a sidenote, I WILL buy Torgue2D soon once I get my next paycheck.
Anyway, I have this datablock in datablocks.cs:
datablock t2dSceneObjectDatablock(EnemyShipConfig)
{
canSaveDynamicFields = "1";
Layer = "3";
size = "64 64";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionCallback = true;
CollisionLayers = "3";
CollisionDetectionMode = "POLYGON";
CollisionPolyList = "0.00 -0.791 0.756 0.751 -0.746 0.732";
UsesPhysics = "0";
Rotation = "-90";
WorldLimitMode = "KILL";
WorldLimitMax = "880 360";
WorldLimitMin = "-765 -436";
minFireRate = "2000";
maxFireRate = "1200";
laserSpeed = "800";
minSpeed = "100";
maxSpeed = "150";
};This is an exact reproduction of an object that I have in my level. So far, I just used clone() to get as many enemies as I need. It is a r-type style shooter, so I need a variable amount of enemies. Since clone() spams my log, I decided to use datablocks, since it is also more flexible.
Quote:Con::execute - 0 has no namespace: onRemoveFromScene
However, once spawning begins, my game freezes and crashes:
function SpawnEnemy()
{
//%spawnedEnemy = EnemyShipMaster.clone(true);
%spawnedEnemy = new t2dStaticSprite()
{
class = "EnemyShip";
sceneGraph = $global_sceneGraph;
datablock = "EnemyShipConfig";
imageMap = "starshipImageMap";
layer = 3;
};
%speed = getRandom(%spawnedEnemy.minSpeed, %spawnedEnemy.maxSpeed);
%y = getRandom(-320, 320);
// Set Properties
%spawnedEnemy.setPositionX(700);
%spawnedEnemy.setPositionY(%y);
%spawnedEnemy.setVisible(true);
%spawnedEnemy.setLinearVelocityX( -%speed );
%spawnedEnemy.setTimerOn( getRandom( %spawnedEnemy.maxFireRate, %spawnedEnemy.minFireRate ) );
}
// Definition of $global_sceneGraph from game.cs:
$global_sceneGraph = sceneWindow2D.loadLevel(%level);If you need to know more please ask and I please answer it is driving me crazy :D.Thanks for reading :).
About the author
Torque Owner MrSpaceGame
Default Studio Name
First of all, in the documentation it says that you need the datablock with the Keyword "datablock". In a different place on the same page in the documentation it says you need to use "dataBlock".
The real and correct keyword is "config".
The following changed code works:
datablock t2dSceneObjectDatablock(EnemyShipConfig) { canSaveDynamicFields = "1"; Layer = "3"; size = "64 64"; CollisionActiveSend = "1"; CollisionActiveReceive = "1"; CollisionPhysicsReceive = "0"; CollisionPhysicsSend = "0"; CollisionCallback = true; CollisionLayers = "3"; CollisionDetectionMode = "POLYGON"; CollisionPolyList = "0.00 -0.791 0.756 0.751 -0.746 0.732"; UsesPhysics = "0"; Mass = "0"; Rotation = "-90"; WorldLimitMode = "KILL"; WorldLimitMax = "880 360"; WorldLimitMin = "-765 -436"; minFireRate = "2000"; maxFireRate = "1200"; laserSpeed = "800"; minSpeed = "100"; maxSpeed = "150"; }; function SpawnEnemy() { %spawnedEnemy = new t2dStaticSprite(EnemyShip) { sceneGraph = $global_sceneGraph; config = "EnemyShipConfig"; imageMap = "starshipImageMap"; }; %speed = getRandom(%spawnedEnemy.minSpeed, %spawnedEnemy.maxSpeed); %y = getRandom(-320, 320); // Set Properties %spawnedEnemy.setPositionX(700); %spawnedEnemy.setPositionY(%y); %spawnedEnemy.setVisible(true); %spawnedEnemy.setLinearVelocityX( -%speed ); %spawnedEnemy.setTimerOn( getRandom( %spawnedEnemy.maxFireRate, %spawnedEnemy.minFireRate ) ); }