@@ -54,6 +54,10 @@ func add_action(params: Dictionary) -> Dictionary:
5454 if action .is_empty ():
5555 return ErrorCodes .make (ErrorCodes .MISSING_REQUIRED_PARAM , "Missing required param: action" )
5656
57+ if deadzone < 0.0 or deadzone > 1.0 :
58+ return ErrorCodes .make (ErrorCodes .VALUE_OUT_OF_RANGE ,
59+ "deadzone must be in [0.0, 1.0] (got %s ). Typical values are 0.2-0.5; default is 0.5." % deadzone )
60+
5761 if InputMap .has_action (action ):
5862 return ErrorCodes .make (ErrorCodes .INVALID_PARAMS , "Action '%s ' already exists" % action )
5963
@@ -127,11 +131,13 @@ func bind_event(params: Dictionary) -> Dictionary:
127131 return ErrorCodes .make (ErrorCodes .MISSING_REQUIRED_PARAM , "Missing required param: event_type" )
128132
129133 if not InputMap .has_action (action ):
130- return ErrorCodes .make (ErrorCodes .VALUE_OUT_OF_RANGE , "Action '%s ' not found" % action )
134+ return ErrorCodes .make (ErrorCodes .VALUE_OUT_OF_RANGE ,
135+ "Action '%s ' not found. Call input_map_manage(op='add_action', params={action: '%s '}) first." % [action , action ])
131136
132- var event : InputEvent = _create_event (event_type , params )
133- if event == null :
134- return ErrorCodes .make (ErrorCodes .VALUE_OUT_OF_RANGE , "Unsupported event_type: %s (use key, mouse_button, or joy_button)" % event_type )
137+ var event_or_error = _create_event (event_type , params )
138+ if event_or_error is Dictionary :
139+ return event_or_error
140+ var event : InputEvent = event_or_error
135141
136142 InputMap .action_add_event (action , event )
137143
@@ -151,35 +157,45 @@ func bind_event(params: Dictionary) -> Dictionary:
151157 }
152158
153159
154- func _create_event (event_type : String , params : Dictionary ) -> InputEvent :
160+ ## Returns an InputEvent on success, or a Dictionary error on failure.
161+ ## Caller must check ``result is Dictionary`` before treating it as an event.
162+ func _create_event (event_type : String , params : Dictionary ):
155163 match event_type :
156164 "key" :
157165 var ev := InputEventKey .new ()
158166 var keycode_str : String = params .get ("keycode" , "" )
159167 if keycode_str .is_empty ():
160- return null
168+ return ErrorCodes .make (ErrorCodes .MISSING_REQUIRED_PARAM ,
169+ "event_type='key' requires keycode (e.g. 'Space', 'A', 'Enter', 'Escape', 'F1')." )
161170 ev .keycode = OS .find_keycode_from_string (keycode_str )
162171 if ev .keycode == KEY_NONE :
163- return null
172+ return ErrorCodes .make (ErrorCodes .VALUE_OUT_OF_RANGE ,
173+ "Invalid keycode '%s '. Use Godot keycode names like 'A', 'Space', 'Enter', 'Escape', 'F1', 'Left', 'Right'." % keycode_str )
164174 ev .ctrl_pressed = params .get ("ctrl" , false )
165175 ev .alt_pressed = params .get ("alt" , false )
166176 ev .shift_pressed = params .get ("shift" , false )
167177 ev .meta_pressed = params .get ("meta" , false )
168178 return ev
169179 "mouse_button" :
170- var ev := InputEventMouseButton .new ()
171- var button : int = params .get ("button" , 0 )
180+ if not params .has ("button" ):
181+ return ErrorCodes .make (ErrorCodes .MISSING_REQUIRED_PARAM ,
182+ "event_type='mouse_button' requires button (1=left, 2=right, 3=middle, 4=wheel up, 5=wheel down)." )
183+ var button : int = int (params .get ("button" , 0 ))
172184 if button <= 0 :
173- return null
185+ return ErrorCodes .make (ErrorCodes .VALUE_OUT_OF_RANGE ,
186+ "mouse_button button must be > 0 (got %d ). Use 1=left, 2=right, 3=middle, 4=wheel up, 5=wheel down." % button )
187+ var ev := InputEventMouseButton .new ()
174188 ev .button_index = button
175189 return ev
176190 "joy_button" :
177- var ev := InputEventJoypadButton .new ()
178191 if not params .has ("button" ):
179- return null
192+ return ErrorCodes .make (ErrorCodes .MISSING_REQUIRED_PARAM ,
193+ "event_type='joy_button' requires button (JoyButton index, e.g. 0=A/Cross, 1=B/Circle)." )
194+ var ev := InputEventJoypadButton .new ()
180195 ev .button_index = int (params .get ("button" , 0 ))
181196 return ev
182- return null
197+ return ErrorCodes .make (ErrorCodes .VALUE_OUT_OF_RANGE ,
198+ "Unsupported event_type: '%s '. Use 'key', 'mouse_button', or 'joy_button'." % event_type )
183199
184200
185201func _serialize_event (event : InputEvent ) -> Dictionary :
0 commit comments