GuiMenuBar - trouble setting command strings
by Demolishun · in Torque Game Engine · 09/17/2004 (3:50 pm) · 6 replies
This is really strange. I am using code directly out of the GuiEditorMenuBar as a guide, yet it still fails. This is the code I am trying to get working:
// Begin Code
%newObj = "TestGuiWindow";
...
%tempObj = %newObj @ "MenuBar";
new GuiMenuBar(%tempObj)
{
position = "5 22";
//extent = "390 20";
extent = "390 22";
horizSizing = "width"; // Change width with the window
vertSizing = "bottom"; // Maintain distance from top (seems backwards)
};
%tempObj.clearMenus();
%tempObj.addMenu("File", 0);
%tempObj.addMenuItem("File", "New", 1);
%tempObj.scriptCommand["File", 1] = "echo(\"Hello\");" ;
// End Code
The code "echo(\"Hello\");" never gets called when I select the "New" option in the "File" menu. The really wierd thing is the menubar ends up with a dynamic variable called "scriptCommandF" and is set to "echo(\"Hello\");". So it creates a bogus variable and sets it to the correct string? Shouldn't this code be setting an array inside the menubar? I cannot find that array anywhere. I got the example for this code directly out of "GuiEditorGui.gui".
Thanks for any mistakes you can point out,
Frank
// Begin Code
%newObj = "TestGuiWindow";
...
%tempObj = %newObj @ "MenuBar";
new GuiMenuBar(%tempObj)
{
position = "5 22";
//extent = "390 20";
extent = "390 22";
horizSizing = "width"; // Change width with the window
vertSizing = "bottom"; // Maintain distance from top (seems backwards)
};
%tempObj.clearMenus();
%tempObj.addMenu("File", 0);
%tempObj.addMenuItem("File", "New", 1);
%tempObj.scriptCommand["File", 1] = "echo(\"Hello\");" ;
// End Code
The code "echo(\"Hello\");" never gets called when I select the "New" option in the "File" menu. The really wierd thing is the menubar ends up with a dynamic variable called "scriptCommandF" and is set to "echo(\"Hello\");". So it creates a bogus variable and sets it to the correct string? Shouldn't this code be setting an array inside the menubar? I cannot find that array anywhere. I got the example for this code directly out of "GuiEditorGui.gui".
Thanks for any mistakes you can point out,
Frank
About the author
I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67
#2
You need...
%newObj = new GuiMenuBar(%tempObj)
{
position = "5 22";
//extent = "390 20";
extent = "390 22";
horizSizing = "width"; // Change width with the window
vertSizing = "bottom"; // Maintain distance from top (seems backwards)
};
MissionCleanup.add(%newObj);
then...
%tempObj.clearMenus();
%tempObj.addMenu("File", 0);
%tempObj.addMenuItem("File", "New", 1);
%tempObj.scriptCommand["File", 1] = "echo(\"Hello\");" ;
Also, you may already know this but writing this command....
%tempObj.scriptCommand["File", 1] = "echo(\"Hello\");" ;
Will be read the same as this command....
%tempObj.scriptCommandFile_1 = "echo(\"Hello\");" ;
Will that be read correctly when called?
09/17/2004 (5:54 pm)
First off I think you may have a problem here....You need...
%newObj = new GuiMenuBar(%tempObj)
{
position = "5 22";
//extent = "390 20";
extent = "390 22";
horizSizing = "width"; // Change width with the window
vertSizing = "bottom"; // Maintain distance from top (seems backwards)
};
MissionCleanup.add(%newObj);
then...
%tempObj.clearMenus();
%tempObj.addMenu("File", 0);
%tempObj.addMenuItem("File", "New", 1);
%tempObj.scriptCommand["File", 1] = "echo(\"Hello\");" ;
Also, you may already know this but writing this command....
%tempObj.scriptCommand["File", 1] = "echo(\"Hello\");" ;
Will be read the same as this command....
%tempObj.scriptCommandFile_1 = "echo(\"Hello\");" ;
Will that be read correctly when called?
#3
It is kind of wierd what the editor shows for the array, but as long as it works!
Thanks,
Frank
09/17/2004 (6:33 pm)
Hey Eustacia, it works great!It is kind of wierd what the editor shows for the array, but as long as it works!
Thanks,
Frank
#4
Why would I need to use "missionCleanup.add()" function?
I am adding this menubar to a GuiWindowCtrl already. I guess I did not show that in the code.
Thanks,
Frank
09/17/2004 (6:37 pm)
Gonzo,Why would I need to use "missionCleanup.add()" function?
I am adding this menubar to a GuiWindowCtrl already. I guess I did not show that in the code.
Thanks,
Frank
#5
09/17/2004 (6:53 pm)
As long as it's being added somewhere before you start executing commands on it, it should be fine.
#6
09/17/2004 (9:05 pm)
Why add before? Right now I am adding after I configure it. It seems to attach itself to GuiSimGroup before I attach it to my GuiWindowCtrl.
Torque Owner Eustacia Green
function GuiMenuBar::onMenuItemSelect(%this, %menuId, %menu, %itemId, %item) { if(%this.scriptCommand[%menu, %itemId] !$= "") eval(%this.scriptCommand[%menu, %itemId]); else error("No script command defined for menu " @ %menu @ " item " @ %item); }