Game Development Community

Cloning, datablocks, ?

by James Ford · in Torque Game Builder · 05/02/2007 (11:13 pm) · 13 replies

Lets say I'm making a projectile t2dsceneobject by dragging an animatedimage into my level and then setting all its properties, like world limits/collision polligons/etc.. Then what is the prefered way to save and reuse that data to create projectiles dynamically in-game? One idea I had was just turn off its world limits, drag it off the edge of the camera/level, then if you want one, clone it and set its position and turn on the world limits. Or I realize I could just open my level file, cut out the object and paste that code whenever i want to create one... But both of these seem more like "hacks". I "think" this is what datablocks are designed for though, if someone could help explain either datablocks, or who they would handle this please.

Thanks!

#1
05/03/2007 (12:48 am)
Hi James, have you had a look at the beta of 1.5? There's a Template behavior included which seems intended for this sort of situation.
Prior to 1.5 I used a variation of your second option, a 'cast' file full of functions to create objects. It worked just fine and the Hack Police never once showed up.
#2
05/03/2007 (1:59 am)
Actually ive been using 1.5 and am loving it hmmm... I hadn't thought of using behavior in quite that way, but I suppose you could store anything in it...

I was using behavior for assigning keybinds for my player object and for more "behavior" like things but why not use it to set the image/size/everything too, cool.

Then they just need to add a behavior_creator module into the GUI, wee!
#3
05/03/2007 (10:50 am)
(Maybe I'm wrong here, but)
I think you should be using datablocks to initialize/create your objects. Secondly, I haven't looked at the new 1.5 behaviors stuff, or this "template behavior" your talking about. Behaviors for actions, datablocks for data. If I understand the theory though, behaviors could/should possibly be used for different entitys by making the code generic, but now if you start using behaviors to do all the initializing of a specific object, you just screwed yourself because you cant share that code anymore.

Example: I make a behavior for a monster to guard an area. If this behavior also initialized how the monster looks, how can I share this behavior with a differnent entity, like a hero?

Just a thought, good luck.
#4
05/03/2007 (3:15 pm)
Well you can break your behaviors into whatever size chunks you want to enable "sharing". But i see what you mean, datablocks do seem more like that is what they are designed for; however, are datablocks ever a part of TGB 1.5? or earlier TGB versions? From what I've read datablocks are definitely a part of TGE but are they a part of TGB?

I can envision how to create some functions (console functions?) in script to create and return an object without using datablocks... but maybe someone could give an example of doing this with datablocks?
#5
05/03/2007 (4:07 pm)
In TGB they are considered "config datablocks" and were designed more for initialized data - Look for references of t2dSceneObjectDatablock. Im sure in TGE they were designed for more things though. Do a search for datablocks in TGB forums, Ive seen some good discussions.

How to assign:
Basic idea would be you define your config datablocks for some objects in either separate files or all in a config.cs file. In the editor you have your animations loaded. So when your ready to create an object you first place your image/animation into the scene. Then from the Edit pane expand the Scripting rollout and select the config datablock from the dropdown list.

At work, no time for example...sorry.
#6
05/03/2007 (10:07 pm)
I've done some research on config datablocks, thanks for the info. Have there been changes made to config datablocks in 1.5? I noticed there is no longer a datablock dropdown on the "create" tab in the level editor; though, you can still set a datablock for a sceneobject directly under edit.

However, I havent been able to get any datablocks to show up on this list. Where should datablocks be defined to show up on this dropdown menu? Creating them in game.cs didnt work--since i dont think game.cs gets executed until the game is actually running.
#7
05/04/2007 (6:42 am)
James, the datablocks not showing up is a bit of an issue yeah. Same thing with GUI profiles defined in the game, they won't show up in the editor.

What I do is to have two files in the game, profiles.cs (for GUI profiles) and pseudoClasses.cs for config datablocks, then you need to go into the editor scripts and make sure these get executed when you load a project.

Add something like this in \tgb\tools\editorClasses\scripts\projects\projectInternalInterface.ed.cs in the function ProjectBase::_onProjectOpen after setScriptPathExpando("game", %this.gamePath @ "/game" );

exec(expandFileName( "^game/gameScripts/profiles.cs"));
exec(expandFileName( "^game/gameScripts/pseudoClasses.cs"));


There's probably some easier way to fix this, but, ah well. It works.
#8
05/04/2007 (12:08 pm)
Cool, that works.

Is there any way to edit/change datablocks in the editor?
#9
05/04/2007 (12:44 pm)
Thanks a lot Magnus, though it doesn't resolve the fact that I can't create new objects with it in 1.5, it prevent the already existing ones to be erased by the editor, good finding \o/

@James
Basically, to create a datablock easily, you'll have to first create the object in a level, then open the level.t2d, and find the object, then create a script file that you'll exec in game.cs, in this script you write :
datablock t2dsceneobjectdatablock(myprojectile)
{
        //your values
}
In the values, copy/paste the values that are in the object in level.t2d (without mountID and world position, which will be obviously different from one object to another). And here you go :]


And when the script file is loaded, to create a projectile in script :
new t2dstaticsprite() {
      config = "myprojectile";
};
Note that it's working with any type of sceneobject. In 1.3 editor there's also a datablock dropdown menu in the new tab, which is really nice for creating entire levels using only datablocks and nothing else to do (I personally use datablocks a lot and for everything, it simply rocks).
#10
05/04/2007 (1:10 pm)
Benjamin, not really sure what you mean with "can't create objects with it", if you create an object you can still assign it a config datablock in the edit tab.
#11
05/04/2007 (1:49 pm)
I just found out it worked well, I thought the dropdown menu in script menu was bugged, but I didn't really tried. Now it's working ^^'

PS : For those who don't own the pro version : I don't own the .cs sources of the editor, so to make it works, I had to put the same lines of code after line 249 in TGB/main.cs.
#12
05/04/2007 (7:50 pm)
James, modifying your datablocks needs to be done from script otherwise I'm afraid any fields you edit would be on a per object biases and not apply to all objects of a type of datablock.

Also, I just noticed you own the Adventure kit, so Im really surprised by your datablock questions since the adv kit explains a lot of this.
#13
05/04/2007 (10:19 pm)
FYI:
I would really like to see a way to create and edit datablocks from within the editor in future versions.