Closed
Description
Describe the project you are working on
NoGame-APP
Describe the problem or limitation you are having in your project
I'm create a console server app, and client can connect.
in my project, I have many code for debug use prints
function.
when i export project, i don't want console print this info, so i set disable_std_out
in ProjectSettings.
but for some info, like client connect server, client request info etc, i want print this info.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
For now, the application/run/disable_stdout
can't take effect on runtime:
Maybe can implement a method for this:
static func prints_smart(text, always:=false):
if OS.has_feature("editor") or always:
prints(text)
but there was 2 problems:
- in my project, there was so much prints codes need update.
- need to implement much methods like print_debug, printerr etc.
- some info can't take effect like:
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
My code like this:
var disable_stdout = false
func _ready():
if if OS.has_feature("editor"):
disable_stdout = false
else:
disable_stdout = true
ProjectSettings.set_setting("application/run/disable_stdout",disable_stdout)
prints("App Start")
func print_always(text):
if disable_stdout:
ProjectSettings.set_setting("application/run/disable_stdout",false)
prints(text)
ProjectSettings.set_setting("application/run/disable_stdout",true)
else:
prints(text)
func _on_client_connect():
print_always("client connect")
func _on_client_req_info(info):
print_always("client req info:%s"%info)
req_info(info)
func req_info(info):
prints(info.id)
prints(info.name)
prints(info.many_info)
func quit():
prints("quit")
If this enhancement will not be used often, can it be worked around with a few lines of script?
In the Editor, it should prints:
>App Start
>client connect
>client req info: aaa
>info.id = 564564563165
>info.name = "asfafdasdfasf"
>info.many_info = asdfasfasdf
sadfdsaf
saf
as
f
safd
>quit
For exported app, it should prints:
>App Start
>client connect
>client req info: aaa
Other a simple example:
func _ready():
test(true)
test(false)
test(true)
test(false)
func test(disable:bool):
ProjectSettings.set_setting("application/run/disable_stdout",disable)
if disable:
prints("Disable, This line can't print")
else:
prints("Enable, This line should print")
I wish output was:
>Enable, This line should print
>Enable, This line should print
Is there a reason why this should be core and not an add-on in the asset library?
No, it should be core