My in-console debugger

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Juan

I have recently built an in-console debugger which allows me to collect items when pressed. I’ve implemented a rich text label with an in-line edit node, which allows me to enter a command to be executed in run time, and collect my object. The problem is that I would also like to output a message that says, “You have successfully collected a banana”. I know how to do this, so that the message is outputted. However, both of these functions require the same button to be pressed, i.e, Enter.

The problem here is that when I press Enter only the message is output and my object does not disappear. However, when I take away the code for the output of my message, then the banana disappears. Therefore, both functions cannot simultaneously be executed, because they both use the same button.

I’d like a suggestion of how I can get both a command to appear in the console box, and for my item to disappear upon entering collect_item banana, for example.

Much appreciated,


Hi juan you can assign a variable to your input and pass this variable to other nodes via by global script or by onready var.
Like if Input.is_action_pressed(“ui_accept”):

horsecar123 | 2022-03-12 00:17

Hey there, could you elaborate a bit on what the onready var would be, i.e. would it be,

onready var pressedenter

like that, and if I used the global script what exactly would be the variable I am declaring.

Juan | 2022-03-12 22:02

i don’t understand your the problem, why you can’t commit different acts with one single input? could you please share you code or explain what is causing the problem ?

horsecar123 | 2022-03-12 22:41

This is the code for the 2D node called Main:
onready var code_debugger = $CodeDebugger
onready var input_box = get_node(“CodeDebugger/TextEditor”)
onready var output_box = get_node(“CodeDebugger/output”)

func _ready():
code_debugger.connect(“command_submitted”, self, “_on_CodeDebugger_command_submitted”)

func output_text(text):
output_box.text = str(output_box.text, “\n”, text)

func process_command(text):
var words = text.split(" “)
words = Array(words)
output_text(str(“number of words:”, words.size()))
for w in words:

func _on_TextEditor_text_entered(new_text):

func _on_CodeDebugger_command_submitted(command):
# you could split the command here because it’s a string into
# function_name arg1 arg2 arg3 etc
var args = command.split(" ")
# first substring is the function name
# rest are the arguments of the function
var function_name = args[0]
callv(function_name, args)

func collect_item(item):
var items = get_tree().get_nodes_in_group(item)
var first_item = items[0]
first_item.visible = false

And I have a canvas Layer node, called CodeDebugger:

extends CanvasLayer

signal command_submitted(command)

var command = “”

onready var text_editor = $TextEditor

func _ready():

func _process(_delta):
if Input.is_action_just_pressed(“enter”):
emit_signal(“command_submitted”, text_editor.text.strip_edges())
text_editor.text = “”

Juan | 2022-03-12 22:52

Can’t you just call output_text(text) on the function you’re calling here callv(function_name, args)?

func collect_banana():
    output_text("You have successfully collected a banana")

Kazuren | 2022-03-13 15:32