GUI Scripting: Parsing of Set 'Cmd': Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
m (Geep moved page GUI Scripting to GUI Scripting: Parsing of Set 'Cmd': Original title was way too sweeping for this narrow article)
(Redo titles. Include ref to GUI Scripting Language)
Line 1: Line 1:
== GUI commands ==
''See [[GUI Scripting Language]] for a broader background article.''
 
== Implementation Note - When Parsing GUI Commands of Form 'Set "Cmd" ' ==
''By Tels''


Commands in the main menu GUI with "cmd" as first parameter
Commands in the main menu GUI with "cmd" as first parameter
Line 6: Line 9:


are handled in <tt>idGameLocal::HandleMainMenuCommands()</tt> in ''game/game_local.cpp''.
are handled in <tt>idGameLocal::HandleMainMenuCommands()</tt> in ''game/game_local.cpp''.
=== Original Problem ===


For each of the parts "mycommand", "argument1", "argument2" and sometimes the final ";", the routine is called again.  
For each of the parts "mycommand", "argument1", "argument2" and sometimes the final ";", the routine is called again.  
Line 13: Line 18:
Commands like "play" or "music" are special cases, too, only the first part ("play" or "music") is relayed to the routine, but the argument is not. Thus it seems impossible to recover what sound shader is to be played.
Commands like "play" or "music" are special cases, too, only the first part ("play" or "music") is relayed to the routine, but the argument is not. Thus it seems impossible to recover what sound shader is to be played.


=== Solution ===
=== Implemented Solution ===


The routine therefore predicts how many arguments the current command takes, accumulating them on a stack. And when it has seen enough arguments, handles the command and clears the stack before returning.  
The routine therefore predicts how many arguments the current command takes, accumulating them on a stack. And when it has seen enough arguments, handles the command and clears the stack before returning.  

Revision as of 20:06, 17 May 2022

See GUI Scripting Language for a broader background article.

Implementation Note - When Parsing GUI Commands of Form 'Set "Cmd" '

By Tels

Commands in the main menu GUI with "cmd" as first parameter

set "cmd" "mycommand argument1 argument2;"

are handled in idGameLocal::HandleMainMenuCommands() in game/game_local.cpp.

Original Problem

For each of the parts "mycommand", "argument1", "argument2" and sometimes the final ";", the routine is called again.

One special case is just using "set" "cmd" "mycommand", this will call HandleMainMenuCommands() twice, once with "mycommand" and once with ";" as the menuCommand parameter.

Commands like "play" or "music" are special cases, too, only the first part ("play" or "music") is relayed to the routine, but the argument is not. Thus it seems impossible to recover what sound shader is to be played.

Implemented Solution

The routine therefore predicts how many arguments the current command takes, accumulating them on a stack. And when it has seen enough arguments, handles the command and clears the stack before returning.

Any stray ";" as command is silently skipped.

The routine will also complain if you don't give enough arguments to a command.

Examples

set "cmd" "play sound/meta/menu/mnu_hover";  // will result in "play", and potentially ";"
set "cmd" "log 'Some text here';";           // will result in "log", "Some text here" and ";" - written to the console
set "cmd" "mainmenu_heartbeat";              // will result in "mainmenu_heartbeat" and ";"
set "cmd" "mainmenu_heartbeat;";             // will result in "mainmenu_heartbeat", ";" and ";"

Note: The "log" command only works on MainMenu guis, and only if the executable has been built with the cvar "tdm_debug_mainmenu" set to "1".

See also