Godot: A proper mean to get the list of InputMap actions

Created on 4 Jun 2016  路  9Comments  路  Source: godotengine/godot

Operating system or device - Godot version:
Official 2.0.3stable win64

Issue description (what happened, and what was expected):
I've found no clean way to iterate through InputMap actions, and i've found no way to get the list of actions names.

If I do something like this, this ends up with an error.

    var index = 1 # <------ index 0 seems unavailable
    var action = InputMap.get_action_from_id(index)
    while action != "":
        print(action)
        index+=1
        action = InputMap.get_action_from_id(index)

ERROR: InputMap::get_action_from_id: Condition ' !input_id_map.has(p_id) ' is true. returned: StringName()
At: core\input_map.cpp:74

Steps to reproduce:

Link to minimal example project (optional but very welcome):

enhancement junior job core

Most helpful comment

I think get_action_list(var action) is rather misleading and should be renamed to action_list_events(var action) to go with: action_add_event, action_has_event, action_erase_event and something like get_actions() or even get_action_list() should be used for this new function.
@akien-mga Do you think it's possible to rename it, or will it break too much stuff?

All 9 comments

How about... InputMap.get_action_list()? :D
http://docs.godotengine.org/en/latest/classes/class_inputmap.html

@akien-mga :
Array InputMap.get_action_list(action) requires the name of an action as parameter.
So, I guess the "list" it returns is the list of inputs associated to the action.

What I need is to get the list of the name of all actions stored into the InputMap of the project settings.

I've done the test to be sure, and I was right. .get_action_list(action) returns the list of inputs associated to an action.

It is not what I need.

Hm indeed. It should be implemented then.

I think get_action_list(var action) is rather misleading and should be renamed to action_list_events(var action) to go with: action_add_event, action_has_event, action_erase_event and something like get_actions() or even get_action_list() should be used for this new function.
@akien-mga Do you think it's possible to rename it, or will it break too much stuff?

or instead of changing the name or behavior of get_action_list() , there could be a get_list_of_actions() ?

Well, then you would have InputMap.get_list_of_actions() and InputMap.get_action_list(var action) which is kind of misleading I think. Since it's really just a different wording of the same thing(while behavior is different), and the parameter doesn't explain much.

Try:

var properties = Globals.get_property_list()

for property in properties:
    if not property.name.begins_with("input/"):
        continue
    var name = property.name.substr(property.name.find("/") + 1, property.name.length())
    var id = InputMap.get_action_id(name)

    assert(name == InputMap.get_action_from_id(id))

It's based on InputMap::load_from_globals().

@neikeq : great workaround ! thanks !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nunodonato picture nunodonato  路  143Comments

Angluca picture Angluca  路  100Comments

karroffel picture karroffel  路  144Comments

ghost picture ghost  路  117Comments

adolson picture adolson  路  87Comments