klownboy wrote:I'm not sure why it ends up being broken and accounts for the $toolmen variable being displayed in the main menu.
It gets broken up because $toolmen contains line-breaks which means when this line (+heredoc):
Code: Select all
$savemenu = <<<#SAV
"Save Toolbar|D:\Graphics\Icons\Combined\Customize Toolbar on.ico";
$TB_name = input("Save current toolbar as: ", "Change this text here" , , "s");
writefile("$DIR_TOOLBARS\$TB_name.txt", $TB_build);
"Vertical Toolbars|D:\Graphics\Icons\Combined\Customize Toolbar on.ico";
load ("$toolmen", ,"s");
#SAV;
gets executed it sets $savemenu to:
Code: Select all
"Save Toolbar|D:\Graphics\Icons\Combined\Customize Toolbar on.ico";
$TB_name = input("Save current toolbar as: ", "Change this text here" , , "s");
writefile("$DIR_TOOLBARS\$TB_name.txt", $TB_build);
"Vertical Toolbars|D:\Graphics\Icons\Combined\Customize Toolbar on.ico";
load (""Vertical Toolbars|$ICO_TOOLBARS";
" $toolbars"
toolbar(readfile("$DIR_TOOLBARS\$toolbars.txt"));
", ,"s");
Which you should recognize as an invalid script - the Vertical Toolbars load starts with an empty string (not escaped) and doesn't really end, the " $toolbars" looks like a new script, and the toolbar(readfile...)); lacks indentation making it also look like a script.
klownboy wrote:Was there anything I could have done to correct my original syntax and have it work?
Not really... generating scripts within a script becomes complicated quite easily.
You could have made $toolbars a global or permanent variable, but then you'd have to either set $toolbars after you set $savemenu or do some work to escape $toolbars and prevent it from being resolved within the heredoc. That's a bit of a headache and difficult to manage though.
Another option would have been to just have the script generate separate script files for each menu level and have those be interconnected. Which is an okay approach but slightly sloppy.
I probably would have just constructed a single script with all the main menu items and sub-menu items, then use the labels parameter of load to modify how the menus are displayed. For example:
Code: Select all
"Script Builder"
$subScripts = <<<SUBS
"Sub-Item 1 : _sub_1"
Echo 'test';
"Sub-Item 2 : _sub_2"
Echo 'test2';
SUBS;
$mainScript = <<<MAIN
"Item 1 : item1"
Echo 'item 1';
"Sub Menu... : submenu"
Load '*', 'submenu;-;_sub_1;_sub_2', 's';
MAIN;
$script = $mainScript . <crlf 2> . $subScripts;
Load $script,, 's';
So the main menu actually contains all of the script but the sub-menu items are hidden. The item that shows the sub-menu uses load with the myself resource ('*') but specifies the exact labels to show in the menu. Granted, how I would go about building the $script variable would depend largely on how I'm creating the actual scripts they should contain.
What I really like about this last approach is the contents of $script is exactly what I would normally have in a script file. Thus I can debug the resulting script separately from the generating script by just putting it in a separate file. Moreover, if the creation of the script does not need to happen every time then I can have the generator write the script to a file and I now have a cached script that may reduce execution time, though I'd then need some cache-expiry and script-regeneration-triggering logic.
As I said script generation is just tricky business.