Building a new object with a space in the object name fails
by Steve Lamperti · in Torque Game Engine · 09/28/2007 (9:27 am) · 0 replies
If you add a new object with the world editor creator, it doesn't work if there is a space in the name, and doesn't give you an error message. The code below checks for a space in the name, gives the user a relatively friendly error message if the name is incorrect, and cancels the creation of the object.
This code would replace the existing onOk function in creator/editor/objectBuilderGui.gui.
This code would replace the existing onOk function in creator/editor/objectBuilderGui.gui.
function ObjectBuilderGui::onOK(%this)
{
// get current values
for(%i = 0; %i < %this.numControls; %i++)
%this.field[%i, value] = %this.controls[%i].getValue();
//JSL - check for a space in the name, as this will fail dramatically.
echo("JSL - onOK from Object BuilderGui");
%tempStr = OBObjectName.getValue();
%tempX = strchr(%tempStr," ");
echo("JSL - %tempStr: " @ %tempStr @ " %tempX: " @ %tempX);
if (%tempX !$= "")
{
echo("JSL - found a problem with the object name. (It has a space.)");
MessageBoxOK("Object Builder Failure", "Failed to Create '" @ %tempStr @ "'. Names cannot contain a space.");
%this.NewObject = 0;
}
else
{
//
%file = new FileObject();
%file.openForWrite(%this.scriptFile);
%file.writeLine(%this @ ".newObject = new " @ %this.className @ "(" @ OBObjectName.getValue() @ ") {");
echo(%this @ ".newObject = new " @ %this.className @ "(" @ OBObjectName.getValue() @ ") {");
echo("};");
for(%i = 0; %i < %this.numFields; %i++)
%file.writeLine(" " @ %this.field[%i, name] @ " = \"" @ %this.field[%i, value] @ "\";");
%file.writeLine("};");
%file.close();
%file.delete();
exec(%this.scriptFile);
}
//
if(%this.newObject != 0)
%this.processNewObject(%this.newObject);
%this.reset();
Canvas.popDialog(%this);
}