func _input(event):
match event.as_text():
"A":
do_something()
"W":
do_something_else()
But event.as_text()
won't give you the name you've defined in the input map. If you press the W
key, it will return "W", so i don't know how useful this would be.
However it looks like you could simplify what you have currently by a little bit:
if event.is_action_pressed(str(playern)+"charl"):
p.vel.x = -1
elif event.is_action_pressed(str(playern)+"charr"):
p.vel.x = 1
elif event.is_action_released(str(playern)+"charl"):
p.vel.x = 0
if event.is_action_pressed(str(playern)+"charu"):
p.vel.z = -1
elif event.is_action_pressed(str(playern)+"chard"):
p.vel.z = 1
elif event.is_action_released(str(playern)+"charu"):
p.vel.z = 0
When setting p.vel.z = 0
, i don't think you need to check if it is -1 or 1, because the alternative is that it is 0, and if that is the case, setting it to 0 again won't hurt anything.