Ok. I actually got the answer and it was at my face the hole time!
DaveTheCoder For God's sake GDScript has that capability and it works very well. Well enough that we can get exactly what the error in that GDScript is.
The solution is really simple by the way! It's just to check if the script.reload() isn't OK
Code:
# This code runs inside a CodeEdit, so there's where the "get_text()" comes from
func _on_play_button():
# Create and set the code for a GDScript
var script = GDScript.new()
script.set_source_code(get_text())
print("Script Sourced!")
# Reload the GDScript, so it can run the code and check if it has any errors
var error = script.reload()
if error != OK:
# If it has errors, we printerr to Godot and end this function right here
printerr("error")
return
# If there was no errors, we print a "succesful!" message or something like that
print("Script loaded with no errors!")
# the Object's script is set to this script and it runs!
obj.set_script(script)
By the way script_reload() returns an Error that can be OK, FAILED or ERR_...(meaning that there's a lot of different errors that can be thrown by this method). It was very easy to solve, I just didn't know that script_reload() returned an Error to start with.
PS: If you try this by yourself, you'll need to know that it'll throw an error (In the Godot Engine itself) exactly when the code gets to the script_reload if you're running DEBUG, but by continuing or running it in RELEASE, it works 😃 yay!