Can I create a DataBlock within a Function?
by Nicolai Dutka · in Torque Game Engine Advanced · 07/03/2009 (11:16 pm) · 5 replies
I'm trying to avoid loading unneeded datablocks, so I'd like to create them as needed. I have a new Mission Editor tool that I've created that makes objects. Unfortunately, it doesn't make the object unless the datablock exists. So basically what I need the function to do is check if the datablock exists and if not, create one before creating the object instance.
function makeObject(%data)
{
if(!isDatablock(%data)) //This is line pretty much pseudo-code at this point.. I need help here too
datablock staticShapeData (%data) {
category = "StaticShape";
shapeFile = $objectMakerDTS;
emap = true;
};
%newObject = new staticShape() {
canSaveDynamicFields = "1";
Enabled = "1";
dataBlock = %data;
scale = "1 1 1";
};
}
#2
If your problems is to don't load uneeded datablocks, well, just remove them. Obviously this step should be taken when you are near release, so you know exactly what you need and what is useless.
isDatablock isn't a command, but there is the isObject function that you can use to know is an ID or a string belong to an existing object, and it should work also for datablocks
Edit: Picasso was faster than me :)
07/04/2009 (12:49 am)
For what I know, it doesn't work. Datablocks are static data, and they are transmitted to the clients when the client connects to the server, so if you create a new datablock after the client is connected, this datablock never goes to the client.If your problems is to don't load uneeded datablocks, well, just remove them. Obviously this step should be taken when you are near release, so you know exactly what you need and what is useless.
isDatablock isn't a command, but there is the isObject function that you can use to know is an ID or a string belong to an existing object, and it should work also for datablocks
Edit: Picasso was faster than me :)
#3
One thing I didn't mention that makes a difference here is that, this is not a 'game play' function, it is a function being run by our developer tools for creating objects in the level. ;)
07/04/2009 (12:53 am)
Ok, so I'll use my fallback plan. Every datablock in it's own file, categorized, and NOT executed. Then in the function, 'exec' the file containing the one datablock I need and save that datablock to the mission file so it doesn't go away the next time the mission is loaded.One thing I didn't mention that makes a difference here is that, this is not a 'game play' function, it is a function being run by our developer tools for creating objects in the level. ;)
#4
07/04/2009 (7:22 am)
Have you looked into the ScriptObject and ScriptGroups?? They may help...they allow for the creation of TorqueScript only objects however. I've seen them used to populate bots on a network setup, they're pretty handy objects.
#5
@Rex, as far as I understand, the scriptObjects are not networkable(?)
Edit: probably you were meaning something not related to send them over the network.
07/04/2009 (9:13 am)
Quote:I've seen them used to populate bots on a network setup
@Rex, as far as I understand, the scriptObjects are not networkable(?)
Edit: probably you were meaning something not related to send them over the network.
Torque Owner Ivan Mandzhukov
Liman3D
They are not designed to be created on the fly.
By the way it isn't impossible.
Datablocks are objects and i believe using some sort of isObject() and eval() will work fine.
But you are going into wrong directions where the code is not optimized to work this way.