Jump to content
Sign in to follow this  
ColonelKernel

Cannot execute scripts in command menus that have sub-menus

Recommended Posts

Hi.

I'm having issues activating scripts with command menus that have sub-menus.

For instance, suppose I have created the following command menu:

mount_subMenu = [
	["Mount",true],
	["Car", [2], "#USER:car_subMenu", -5, [["expression", "hint ""Car"" "]], "1", "1"]
];

The hint command (or any other command for that matter) doesn't work right now. But if I remove #USER:car_subMenu from the code then the hint command works.

I also tried doing this but the submenu disappears instantly (the hint command works however):

mount_subMenu = [
	["Mount",true],
	["Car", [2], "", -5, [["expression", "
showCommandingMenu ""#USER:car_subMenu"";
hint ""Car"";
"]], "1", "1"]
];

Is there a way I can fix this?

  • Like 1

Share this post


Link to post
Share on other sites

Not sure what you want to do, but with this I can either active the main menu, and use it to reach the submenu, or start the submenu directly:

car_subMenu = [
    ["Submounting", true],
    ["Kewl-style-vaulting", [2], "", -2, [], "1", "1"]
];

mount_subMenu = [
    ["Mount",true],
    ["Car", [2], "#USER:car_subMenu", -5, [["expression", "hint ""Car"";"]], "1", "1"]
];

showCommandingMenu "#USER:mount_subMenu";
showCommandingMenu "#USER:car_subMenu";

The hint also worked, but in what is shown above it first hints until final choice made. But if I add an expression the submenu choice, then that will run instead.

Share this post


Link to post
Share on other sites

The reason your second example does not work is that it wants to shutdown the command menu when it is done running your expression.

Share this post


Link to post
Share on other sites
2 minutes ago, Muzzleflash said:

Not sure what you want to do, but with this I can either active the main menu, and use it to reach the submenu, or start the submenu directly:


car_subMenu = [
    ["Submounting", true],
    ["Kewl-style-vaulting", [2], "", -2, [], "1", "1"]
];

mount_subMenu = [
    ["Mount",true],
    ["Car", [2], "#USER:car_subMenu", -5, [["expression", "hint ""Car"";"]], "1", "1"]
];

showCommandingMenu "#USER:mount_subMenu";
showCommandingMenu "#USER:car_subMenu";

 

This is an example, so I don't actually want to do anything with it!

I want to run the mount_subMenu first, and via that go to the car_subMenu and run the code prior to reaching that menu. (the actual menu I'm creating stores something in a variable, which is necessary for the submenu)

Share this post


Link to post
Share on other sites
31 minutes ago, Muzzleflash said:

The reason your second example does not work is that it wants to shutdown the command menu when it is done running your expression.

Can I somehow keep it open?! (BTW sleep and waitUntil don't work)

Share this post


Link to post
Share on other sites

Don't sleep or waitUntil inside unscheduled environments like this (or event handlers for example). You can use spawn:

 [["expression", "hint ""Car""; [] spawn {sleep 0.1; showCommandingMenu ""#USER:car_subMenu"";};"]] 

, that works for me (though I do consider it an ugly hack).

  • Like 1

Share this post


Link to post
Share on other sites
11 minutes ago, Muzzleflash said:

Don't sleep or waitUntil inside unscheduled environments like this (or event handlers for example). You can use spawn:


 [["expression", "hint ""Car""; [] spawn {sleep 0.1; showCommandingMenu ""#USER:car_subMenu"";};"]] 

, that works for me (though I do consider it an ugly hack).

Thanks! It works splendidly!

Share this post


Link to post
Share on other sites
13 minutes ago, Muzzleflash said:

that works for me (though I do consider it an ugly hack)

By the way, what do you mean by it being an ugly hack?!

Share this post


Link to post
Share on other sites
22 minutes ago, Muzzleflash said:

Don't sleep or waitUntil inside unscheduled environments like this (or event handlers for example). You can use spawn:


 [["expression", "hint ""Car""; [] spawn {sleep 0.1; showCommandingMenu ""#USER:car_subMenu"";};"]] 

, that works for me (though I do consider it an ugly hack).

It also works without sleep! Awesome!

Share this post


Link to post
Share on other sites
3 hours ago, ColonelKernel said:

By the way, what do you mean by it being an ugly hack?!

Just don't think it is a very clean solution - but it is a solution. The only reason spawn works is because that code is guaranteed to run after the expression itself is done. And the only reason that is guaranteed is because the expression (not the spawn'ed part) runs in the so-called unscheduled environment where scripts run without getting interrupted (unless you sleep or run a loop too long) Ideally, a nice way would allow you to run expression when selecting a submenu, and not only for the "final" items.

3 hours ago, ColonelKernel said:

It also works without sleep! Awesome!

Yep, that is actually how I tested. Thinking back, it was probably a bit silly of me to add it in my answer.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×