Game Development Community

Cannot use WriteDefaults with taml...

by Doctor Fail · in Torque 2D Beginner · 11/09/2013 (7:48 pm) · 2 replies

Ok, this is a followup to the previous post I made. In that post, I remarked that I was getting an odd error of some sort when I was trying to create a GUI. I later found that the problem was not the gui part, but the part I did not mention... I have been trying to take advantage of the capability of the taml manipulation functions in torquescript to learn a bit about gui's. All I want to do is turn on WriteDefaults, and then write out a few GuiControls to file. This effort has been thwarted on every occasion by the engine when it gives a fatal error and crashes; every single time I have tried.

I have pinpointed the problem now. The culprit is this line of code:
%taml.WriteDefaults = true;
or more precisely, it in conjunction with any attempt to write to file.
%gui = new GuiControl()
{
	Profile="GuiDefaultProfile";
    HorizSizing="relative";
    VertSizing="relative";
    Position="0 0";
    Extent="1024 30";
    MinExtent="220 30";
    Visible="1";
};

%taml = new Taml();
%taml.Format = Xml;
%taml.WriteDefaults = true;
%taml.write(%gui, "./log.taml");
%taml.delete();
here is the whole file. For whatever reason, when I attempt to run this file, it's like an atom bomb going off in the code, and I receive this lovely message:

Field value cannot be NULL.
[Retry] [Cancel]

So... If anyone can help me, I am willing to shower you with as much praise as I can muster in one sitting. I have made so little ground with this I feel as though I am going backwards.
If anyone wants to know where I got the idea to do this in the first place:
https://github.com/GarageGames/Torque2D/wiki/Taml-Guide
Go there, and find the section labeled "Writing Defaults".

Thanks for your time,
Doctor Fail

#1
11/10/2013 (4:01 am)
Congratulations, you've found a bug with TAML! Same thing happens with my scripts, although in my case I tried writing out a CompositeSprite with WriteDefaults set to true. I'm sure this is the case with most of the engine classes, as somewhere in the inheritance chain there's bound to be a static field that has NULL for a default.

For now, obviously keep WriteDefaults set to false. To find out more about the static fields for each object, there's the the class list here (is linked from the wiki):

garagegames.github.io/Torque2D/classes.html

That won't tell you their default values though. For that you will have to look in the source files. The default value that TAML ignores is defined in the .h file of each object. An example from guiSpriteCtrl:

static bool writeImageFrame( void* obj, StringTableEntry pFieldName ) { GuiSpriteCtrl* pCastObject = static_cast<GuiSpriteCtrl*>(obj); return pCastObject->isStaticFrameProvider() && pCastObject->getImageFrame() > 0; }

At the very end of that long line of code - 0 is defined as the default, so any frame number greater than zero will be written out.
#2
11/10/2013 (8:42 am)
Could the solution to this problem be disabling the check for a null field value in(?):
SimObject::getPrefixedDataField();
Granted, I have spent almost zero time with the engine's source at the moment, as my c++ skills need some polishing; so I don't know if that method is used for anything else. (I should assume it is)

Anyway, thanks for the assistance, I'll be getting back to the old grind again I suppose.