Code Snippets GDScript

Short texts GDScript 🧑‍💻 Code snippets GDScript ✍️ Reading lists GDScript 👀

Godot EditorPlugin utility to track the currently active editor’s TextEdit instance

var _script_editor = null var _num_searched = 0 var _text_edits = [] var _focused = null signal editor_changed # Requires reference to the ScriptEditor instance. func _init(script_edtitor): _script_editor = script_edtitor _script_editor.connect(“editor_script_changed”, self, ‘_on_editor_script_changed’) _scan_script_editor() func _on_editor_script_changed(script): var old_focus = _focused _scan_script_editor() if(old_focus != _focused): emit_signal(‘editor_changed’) # Scan through the ScriptEditor finding all TextEdits and populating […]

Godot EditorPlugin utility to track the currently active editor’s TextEdit instance

var _script_editor = null var _num_searched = 0 var _text_edits = [] var _focused = null signal editor_changed # Requires reference to the ScriptEditor instance. func _init(script_edtitor): _script_editor = script_edtitor _script_editor.connect(“editor_script_changed”, self, ‘_on_editor_script_changed’) _scan_script_editor() func _on_editor_script_changed(script): var old_focus = _focused _scan_script_editor() if(old_focus != _focused): emit_signal(‘editor_changed’) # Scan through the ScriptEditor finding all TextEdits and populating […]

Godot ObserverCam2D

extends Camera2D # This script turns a Camera2D into a mouse-controllable ObserverCamera # Holding the Middle Mouse button and moving the mouse pans the camera # Mouse Scroll Wheel zooms the camera in and out # Clicking the Middle Mouse button without moving the camera resets the camera # Checking ‘force_current’ will continually set this […]

State Machine for Godot

extends Node onready var state = null onready var previous_state = null onready var state_name = “” func _ready(): set_state(get_children()[0].name) func _physics_process(delta): if state and state.has_method(“physics_process”): state.physics_process(delta) func _process(delta): if state and state.has_method(“process”): state.process(delta) func _unhandled_input(event): if state and state.has_method(“unhandled_input”): state.unhandled_input(event) func set_state(s): state_name = s var new_state = get_node(s) if state != null: if […]

something witness-y but not really

extends Area # Has a bunch of collisionshape children to check different squares against. # Not the most optimized system since it’s multiple objects vs contained in one plane. # Z clipping in picking is also an issue class_name PuzzlePanel const HALF_PI := 1.570796 enum DIRECTIONS { UP, RIGHT, DOWN, LEFT } var tile_grid := […]