I'm writing a debug console for a project. I want it to know who is sending the debug messages to it can decide which ones to display or not based off of an ignore list. That way I don't have to comment out all my debug messages for X when I start working on Y, I can just tell the debug console to ignore X.
Since Godot doesn't have any code tracing, I've been sending that info as a parameter. Which is fine, except I have to alter the code for every function because I don't know if there's a way for a function to know it's own name.
Here is the barebones what I have so far:
extends Control
#VARS--------------------------
var ME
#SIGNALS-----------------------
signal DebugPrintLine(from, txt)
signal DebugPrintNewLine(from)
#Functions---------------------
func _ready():
#assign ME to current script path
ME = get_script().get_path().right("res://Scripts/".length())
func _on_LoadFileDialog_file_selected(path):
#assign ME_text to ME + func name
var ME_txt = ME + "/" + "_on_LoadFileDialog_file_selected()"
#send debug messages
emit_signal("DebugPrintNewLine", ME_txt)
emit_signal("DebugPrintLine", ME_txt, "Opening: " + path)
#do other stuff
If I could change
var ME_txt = ME + "/" + "_on_LoadFileDialog_file_selected()"
to something like
var ME_txt = ME + func_name()
That would make the scalability of this workaround that much easier.. I could just copy that line to the top of every function instead of having to tweak it each time.
I've looked into getmethodlist() and I can narrow it down to (mostly)my functions... but that's about it since I don't know how to identify the exact function I want without tweaking the code each time.
I've also thought about reading the gd file as text and getting function names that way.. but it's still the same problem.
Any suggestions would be appreciated!
Thanks for reading all this =]
EDIT: If possible, I need a solution which will work during runtime, not just in debug mode.