ActionMap Concept

Discuss the development of Reality Factory 2
Post Reply
User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

ActionMap Concept

Post by paradoxnj » 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):

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");
}
-- 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:

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");
}
You can bind every single key on the keyboard and every single button on the mouse (including the Windows Key and foreign keys).
Many Bothans died to bring you this signature....

User avatar
ardentcrest
Posts: 735
Joined: Wed Jan 25, 2006 10:55 pm
Location: Ireland

Re: ActionMap Concept

Post by ardentcrest » Mon Jan 26, 2009 11:05 am

Let me get this right.

Say you want to show a map on level 1 using the "M" key, but only when you have the map, and on level 2 you want the show the map using the "N" key you would use the above script.

I.e. you can config any key to do anything at any time while playing the level.


Nice.(If I have it right).
He's a Bot Jim, But not as we know It.

User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

Re: ActionMap Concept

Post by paradoxnj » Mon Jan 26, 2009 3:12 pm

That is one use. Here's another...

Let's say that you have 2 characters in your game. You want to transfer control from one character to another, but the other character has different actions. You would create an ActionMap specifically for that character and set it as current everytime you switch to that character in game.

Another scenario, your main menu needs to use the arrow keys...but your player controls use the arrow keys for movement. You would create an action map for the main menu, and set it current when the menu is active.

In short...an actionmap allows you to remap your keyboard and mouse for a specific situation in your game.

You don't have to setup your input this way...it just makes life more convienient. You can just use the global action map with a series of if/then statements if you wish.
Many Bothans died to bring you this signature....

User avatar
ardentcrest
Posts: 735
Joined: Wed Jan 25, 2006 10:55 pm
Location: Ireland

Re: ActionMap Concept

Post by ardentcrest » Mon Jan 26, 2009 3:18 pm

I like a lot.

So In your opion is this script engine better then python. :?:
He's a Bot Jim, But not as we know It.

User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

Re: ActionMap Concept

Post by paradoxnj » Mon Jan 26, 2009 9:50 pm

See this for the answer to ardentcrest's question.
Many Bothans died to bring you this signature....

Post Reply