ActionMap Concept
Posted: Mon Jan 26, 2009 2:06 am
RF is lacking in the ability to script input actions. To alleviate that problem, I have come up with the concept of Action Maps. I borrowed some of the design from the Torque Game Engine, but it works differently for RF2. A little explanation is in order here...
NOTE: All script examples in this post are done in Squirrel script. RF2's primary scripting language is still Python at the moment.
Action maps are key/mouse mappings that are defined for the game. Let's say you don't want to use ESC to get to your menu...now you don't have to...just bind the key that you want to a script function that displays the menu.
Example (in Squirrel code):
-- Let's say you want completely different key combinations for the menu. Just create a new action map and when you create your function to switch to the menu, just set the current action map to be your new action map.
Example:
You can bind every single key on the keyboard and every single button on the mouse (including the Windows Key and foreign keys).
NOTE: All script examples in this post are done in Squirrel script. RF2's primary scripting language is still Python at the moment.
Action maps are key/mouse mappings that are defined for the game. Let's say you don't want to use ESC to get to your menu...now you don't have to...just bind the key that you want to a script function that displays the menu.
Example (in Squirrel code):
Code: Select all
// Global action map is the default action map created by the RF2 shell...
local map = RF2GetInput().GetActionMap("Global");
map.bind(KEY_F12, "show_menu");
function show_menu()
{
RF2GetGame().setState("MenuState");
}
Example:
Code: Select all
// Global action map is the default action map created by the RF2 shell...
local map = RF2GetInput().GetActionMap("Global");
map.bind(KEY_F12, "show_menu");
map = RF2ActionMap("MenuMap");
map.bind(KEY_ESC, "menu_exit");
function show_menu()
{
RF2GetGame().setState("MenuState");
RF2GetInput().setCurrentActionMap("MenuMap");
}
function menu_exit()
{
RF2GetGame().setState("GameState");
RF2GetInput().setCurrentActionMap("Global");
}