How to send the result of the script to 2D Mainscreen?

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

For example,I am writing code on Godot engine(Script).

var a : int = 7
var b : int = 3
func run():
     print(7 / 3)

The final code process(result) will be show on output screen.(main viewport)


I want to know how to send the result of the script to 2D Mainscreen(main viewport).I mean 2D mainscreen that is near 3D,Script,AssetLib on Godot’s Editor Interface.

edit: What my script doing is calculate the result from 7/3 and print the result to the viewport.

:bust_in_silhouette: Reply From: pcanella

You may want to use a Singleton/Autoload pattern for this. Here’s a couple of links that explain this:

Basically you can share back and forth with the Singleton as kind of a “shared” global class.

So for example if you want to save the result, in your Singleton you’d have something like

var shared_data = null

Singleton.set("shared_data", somedatayouwanttosave)


Note, those examples can be simplified to just:

Singleton.shared_data = "my new value"


var local_var = Singleton.shared_data

jgodfrey | 2023-03-15 23:57

oh yes! Good call out :slight_smile:

pcanella | 2023-03-16 00:04