Godot Version
3.5
Question
Hi. Sorry if i phrased this question in a confusing manner. I am having trouble remembering what this thing is called, which is part of why I’m asking here instead of keeping searching.
I am having a problem figuring out how to verify the input for a keybinding system. basically, I want to verify if the player hits a single character (ideally including white space, but lets start small). the goal is to make it so that the character hit can be used for a key to press an action, instead of the action is is by default bound to. basically, custom keybinds.
the error message I’m getting right now is that it cannot convert argument 2 form string to object. I understand that this means that the method ‘wants’ an object, but I am giving it a string. I’m not quite sure how to convert it to an object, however.
… I also still do need to do input checking.
I have a bit of a franken code at the moment, so bear with me, but here it is:
extends Control
var action_string
enum ACTIONS{ATTACK, INTERACT, PAUSE, INVENTORY, YES, NO}
# Called when the node enters the scene tree for the first time.
func _ready():
set_keys()
func set_keys():
for j in ACTIONS:
if !InputMap.get_action_list(j).empty():
#we need to get teh current assignemtns
var temp_line_edit = get_node("Panel/ScrollContainer/VBoxContainer/HBoxContainer" + str(j) + "/" + str(j) + "LineEdit")
#print ("Panel/ScrollContainer/VBoxContainer/HBoxContainer" + str(j) + "/" + str(j) + "LineEdit")
#print (temp_line_edit)
temp_line_edit.set_text(InputMap.get_action_list(j)[0].as_text())
func change_key(new_key):
#delete key of pressed button
if !InputMap.get_action_list(action_string).empty():
InputMap.action_erase_event(action_string, InputMap.get_action_list(action_string)[0])
#check if new key was assigned somewhere
for i in ACTIONS:
if InputMap.action_has_event(i, new_key):
InputMap.action_erase_event(i, new_key)
#add new key
InputMap.action_add_event(action_string, new_key)
set_keys()
func _on_ATTACKButton_pressed():
action_string = "ATTACK"
#print ("I am changing the attack button bind")
#the line edit is bieng null atm
var line_edit = get_node("Panel/ScrollContainer/VBoxContainer/HBoxContainerINTERACT/LineEdit")
print (line_edit)
var key = line_edit.get_text()
#line edit text is AWLAYS returning space that is werid right?
print (key)
change_key(key)
func _on_ATTACKLineEdit_text_changed(new_text):
action_string = "ATTACK"
change_key(new_text)
Let me know if I need to provide more information and I’d be glad to! thanks to anyone who can help!