Create Ruby files
Creating a Ruby file from the FileSystem
To create a Ruby file, right-click within the FileSystem and select Create New → DSL/boot *.rb.
A dialog will appear—check that the file name is correct, then press OK to continue.
A Ruby file should now be created.
Opening a Ruby file
To edit a Ruby file, double-click the .rb
file in the FileSystem.
Its content should now appear in the editor on the main screen.
Alternatively, if the main screen is set to ReDScribe, you can open a file using fuzzy search.
Try pressing Ctrl-o
(or Command-o
on macOS).
Saving a Ruby file
You can save the file by pressing Ctrl-s
(or Command-s
on macOS).
Let's try editing the Ruby file in the editor as shown below, then save it.
def greeting
Godot.emit_signal :greeting, "Hello from Ruby"
end
Executing a Ruby file from GDScript
First, create a scene and attach a GDScript file as shown below.
extends Control
@export var res : ReDScribe
func _ready() -> void:
res.channel.connect(_subscribe)
res.perform('greeting')
func _subscribe(key: StringName, payload: Variant) -> void:
print_debug("[subscribe] ", key, ": ", payload)
@export
is an annotation that allows member variables to be edited in Godot's Inspector.
You should now see the Res property displayed in the Inspector.
Click the Res property and select New ReDScribe.
Then, click the file icon next to Boot File and choose the boot.rb
file you created earlier.
After making your selection, go ahead and run the scene.
The Output panel should now displayed something like the following:
[subscribe] greeting: Hello from Ruby
At: res://src/06.create_ruby_files/control.gd:12:_subscribe()
In GDScript, you simply write:
res.perform('greeting')
By using ReDScribe's boot_file variable like this, you can maintain a clean seperation between Ruby and GDScript.
Try making active use of boot_file to keep your workflow organized and expressive.