Game Development Community

Persisting a level with Taml

by Michael Smith · in Torque 2D Beginner · 03/23/2013 (9:30 pm) · 5 replies

I have populated a SandboxScene with all manner of SceneObjects, both cheerful and explosive. Now I wish to persist them in a Taml file so that I can encapsulate them as a level. I tried the direct approach:

TamlWrite( SandboxScene, "level.taml" );

This made a nice file, but reading it back in did not work:

function MyModule::reset( %this )
{
SandboxScene.clear(); // Clear the scene.
TamlRead("level.taml");
return;
}

Predictably, the Sandbox did not want its existing Scene to be written over by the incoming information.

What is a good way to persist this information and load it when wanted? SceneObjectSet() looks promising for this, but I could not find an example in use. Is it the way to go? Is there a toy that demonstrates SceneObjectSet()?

Included in the level are few unique SceneObjects that I need to reference at the module level. Currently I have their IDs as fields in my module class, "MyModule.player" and so forth. Am I correct in assuming I can get similar functionality by using names? (For example, setName("player") on my player Sprite.)

Thanks for your help! And kudos to capnlove and doodaddy64 for the new Getting Started guide and the Behavior tutorial!

About the author

Bible translator by day-- game programmer by night


#1
03/24/2013 (4:49 am)
@Michael - Have you watched my video tutorial for this?


You mainly want to clear the name of the scene before you persist it. Additionally, if you wish to keep using the Sandbox environment, use the setCustomScene function. That will allow you to load different scenes smoothly in the Sandbox project.
#2
03/24/2013 (6:07 pm)
Excellent. The video is very clear and it solved my problems. Thanks!
#3
03/24/2013 (6:20 pm)
Now I have a followup question. In a scene containing joints, are the joint IDs guaranteed to persist accurately or are they like Object IDs?

<Scene>
<Scene.Joints>
<Revolute>
<Sprite
TamlRefId="1" /> <--- This field here!
<Sprite
TamlRefId="2" />
</Revolute>
</Scene.Joints>
</Scene>
#4
03/25/2013 (12:58 am)
Joint Ids are not persisted but and those are not joint Ids, they are Taml object references and are generated by TAML itself during persistence and are part of its schema.

The objects involved don't know about these references nor are they involved in them.

Essentially when Taml sees an object that is being persisted inside the TAML file and then it is referenced elsewhere inside the same file then it sets up an Id and reference. The object that is being referred to has an attribute of "TamlId=" and the item referencing it will have a "TamlRefId=".

If the example above, the <Sprite>s being referenced by the joint are objects "1" and "2" which you'll find elsewhere in the file as TamlId="1" and TamlId="2".

Joint Ids are like SimObjectIds, they are allocated upon generation and are volatile across sessions.
#5
04/30/2013 (9:05 pm)
Thanks for the video, made everything clear!
So far, I'm a big fan of the move to TAML. (And persistence in general, I suppose).

Thanks again!