Hi, I'm pretty new to this engine, but I think for new people like me this could be usefull:
extends Node
# Declare member variables here. Examples:
var inputRegisterForAction = {}
# Called when the node enters the scene tree for the first time.
func _ready():
inputRegisterForAction["Space"] = [["Jump","JumpPressed","JumpReleased"]]
inputRegisterForAction["Kp 0"] = [["Jump","JumpPressed","JumpReleased"]]
inputRegisterForAction["BUTTON_LEFT"] = [["Shoot","ShootPressed","ShootReleased"]]
inputRegisterForAction["S"] = [["Shoot","ShootPressed","ShootReleased"]]
inputRegisterForAction["BUTTON_RIGHT"] = [["Interact","InteractPressed","InteractReleased"]]
inputRegisterForAction["D"] = [["Interact","InteractPressed","InteractReleased"]]
pass # Replace with function body.
func _input(event):
var index = event.as_text().find("button_index=");
var hasIndex = (index >= 0);
index = (index + "button_index=".length()) if (hasIndex) else -1;
var lenght = event.as_text().find(",", index) - index;
var complexKey = event.as_text().substr(index, lenght) if (hasIndex) else "";
var selectedTextInput = complexKey if inputRegisterForAction.has(complexKey) else event.as_text();
#print(event.is_action_pressed("Jump"))
if inputRegisterForAction.has(event.as_text()) || inputRegisterForAction.has(complexKey):
for action in inputRegisterForAction[selectedTextInput]:
if event.is_action_pressed(action[0]):
call(action[1])
if event.is_action_released(action[0]):
call(action[2])
pass
func JumpPressed():
print("JUMP Pressed")
pass
func JumpReleased():
print("JUMP Pressed")
pass
func ShootPressed():
print("SHOOT Pressed")
pass
func ShootReleased():
print("SHOOT Released")
pass
func InteractPressed():
print("Interact Pressed")
pass
func InteractReleased():
print("Interact Released")
pass
```
I think this code is less intensive on the machine, more scalable and more costumizable compared to code like this:
```
extends Node
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _input(event):
if(event.is_action_pressed("Jump")):
JumpPressed()
if(event.is_action_released("Jump")):
JumpReleased()
if(event.is_action_pressed("Shoot")):
ShootPressed()
if(event.is_action_released("Shoot")):
ShootReleased()
if(event.is_action_pressed("Interact")):
InteractPressed()
if(event.is_action_released("Interact")):
InteractReleased()
pass
func JumpPressed():
print("JUMP Pressed")
pass
func JumpReleased():
print("JUMP Pressed")
pass
func ShootPressed():
print("SHOOT Pressed")
pass
func ShootReleased():
print("SHOOT Released")
pass
func InteractPressed():
print("Interact Pressed")
pass
func InteractReleased():
print("Interact Released")
pass
```
I could be wrong, I'll take any suggestions if so :)