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

From The DarkMod Wiki
Jump to navigationJump to search
No edit summary
m (add play/music handling)
Line 10: Line 10:


One special case is just using "set" "cmd" "mycommand", this will call <tt>HandleMainMenuCommands()</tt> twice, once with "mycommand" and once with ";" as the ''menuCommand'' parameter.  
One special case is just using "set" "cmd" "mycommand", this will call <tt>HandleMainMenuCommands()</tt> 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.


=== Solution ===
=== Solution ===
Line 21: Line 23:
=== Examples ===
=== Examples ===


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


== See also ==
== See also ==

Revision as of 19:09, 12 September 2011

GUI commands

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.

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.

Solution

The routine there fore predicts how much arguments the current command takes, accumulates 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 give not 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 ";"
set "cmd" "mainmenu_heartbeat";              // will result in "mainmenu_heartbeat" and ";"
set "cmd" "mainmenu_heartbeat;";             // will result in "mainmenu_heartbeat", ";" and ";"

See also