Godot Version
4.6.3 stable
Question
Hello, I am trying to make a "input_handler" script where every frame it checks for inputs using a function, I would assume a _process one, returning "N" if no movement inputs are received and "None" if no attack inputs are received. I can't return the variables input and att_input into another file though.
extends Node
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var input = "N"
var att_input = "None"
if Input.is_action_pressed("Down"):
if Input.is_action_pressed("Left"):
input = "DownLeft"
elif Input.is_action_pressed("Right"):
input = "DownRight"
elif not Input.is_action_pressed("Up"):
input = "Down"
if Input.is_action_pressed("Up"):
if Input.is_action_pressed("Left"):
input = "UpLeft"
elif Input.is_action_pressed("Right"):
input = "UpRight"
elif not Input.is_action_pressed("Down"):
input = "Up"
if Input.is_action_pressed("Right"):
if Input.is_action_pressed("Down"):
input = "DownRight"
elif Input.is_action_pressed("Up"):
input = "UpRight"
elif not Input.is_action_pressed("Left"):
input = "Right"
if Input.is_action_pressed("Left"):
if Input.is_action_pressed("Down"):
input = "DownLeft"
elif Input.is_action_pressed("Up"):
input = "UpLeft"
elif not Input.is_action_pressed("Right"):
input = "Left"
if Input.is_action_pressed("Light"):
att_input = "Light"
if Input.is_action_pressed("Medium"):
att_input = "Medium"
if Input.is_action_pressed("Heavy"):
att_input = "Heavy"
if Input.is_action_pressed("Unique"):
att_input = "Unique"
print(input)
print(att_input)
return input
return att_input
This scene works perfectly, every frame, which I capped at 60 FPS in the project settings, it checks for my inputs and prints out the movement (var input) one and the attack one (var att_input). My idea is, I want to put this scene as a child node in my player scene, so I can, after returning input and att_input with this process function, interpret it and make stuff happen(moving left to right, attacking and animation playing). I do this so I can easily make new characters and just use the same input_handler scene. But I canât understand how to return the input and att_input from this function to another script, Iâve tried âget_nodeâ and @onready var input = $InputHandler._process or something of the sorts and canât figure out what to do, is it because _process is a function that returns void? I really canât wrap my head around this. (I understand maybe input_handler isnât the right name because it doesnât actually âhandleâ the inputs but thatâs the least of my worries right now.) Any help would be appreciated, thanks. Also I understand that maybe the code isnât optimized to itâs fullest but since this is my first time actually working with GDScript I donât expect it to be, so I would appreciate it if you would solely focus on the issue at hand and not some nitpicky details that I might be able to work on after I understand the logic involved with the main issue, would still be helpful of course, just not as âimportantâ.
