This is the code for the 2D node called Main:
onready var codedebugger = $CodeDebugger
onready var inputbox = getnode("CodeDebugger/TextEditor")
onready var outputbox = get_node("CodeDebugger/output")
func ready():
codedebugger.connect("commandsubmitted", self, "onCodeDebuggercommandsubmitted")
inputbox.grab_focus()
func outputtext(text):
outputbox.text = str(output_box.text, "\n", text)
func processcommand(text):
var words = text.split(" ")
words = Array(words)
words.erase("")
outputtext(str("number of words:", words.size()))
for w in words:
output_text(w)
func onTextEditortextentered(newtext):
inputbox.clear()
outputtext(newtext)
processcommand(newtext)
func onCodeDebuggercommandsubmitted(command):
# you could split the command here because it's a string into
# functionname arg1 arg2 arg3 etc
var args = command.split(" ")
# first substring is the function name
# rest are the arguments of the function
var functionname = args[0]
args.remove(0)
callv(function_name, args)
func collectitem(item):
var items = gettree().getnodesingroup(item)
var firstitem = 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():
pass
func process(delta):
if Input.isactionjustpressed("enter"):
emitsignal("commandsubmitted", texteditor.text.stripedges())
texteditor.text = ""