This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class_name ArrayResource | |
extends Resource | |
var _values = []: | |
set(value): | |
_values = value | |
emit_changed() | |
func _init(initial_values: Array = []) -> void: | |
if not initial_values.is_empty(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## For a beginner-friendly version of the following (more advanced users likely will get better use of the below, | |
## if you're just starting out...), see this new gist: | |
## https://gist.github.com/WolfgangSenff/0a9c1d800db42a9a9441b2d0288ed0fd | |
This document represents the beginning of an upgrade or migration document for GDScript 2.0 and Godot 4.0. I'm focusing on 2D | |
at the moment as I'm upgrading a 2D game, but will hopefully have more to add for 3D afterward. | |
## If you want more content like this, please help fund my cat's medical bills at https://ko-fi.com/kyleszklenski - thank you very much! On to the migration guide. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class_name DaisyChain | |
extends RefCounted | |
# Basic signal with early stop implementation | |
var _callables = [] | |
func chain(callable: Callable) -> DaisyChain: | |
_callables.push_back(callable) | |
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends CharacterBody2D | |
class_name Enemy | |
@export var MoveSpeed : float | |
var player : Player | |
func _ready() -> void: | |
Events.player_ready.connect(_on_player_ready) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Beginner-friendly GDScript 1 to GDScript 2 Conversion Guide | |
First and foremost, this should not be considered a replacement for the official migration guide, | |
found at https://docs.godotengine.org/en/latest/tutorials/migrating/upgrading_to_godot_4.html! | |
Instead, this document is intended to be a friendly guide to helping you upgrade your projects from | |
GDScript 1 to 2. To do this, I'm going to list the most common conversions I've run into while upgrading | |
a few of my games and tools. This document is written as of the first release candidate version of Godot 4.0. | |
The first thing to do when converting a project (no need if you're starting from new) is to either have your | |
project in source control, or make a duplicate of your entire project's folder and rename it. This will |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ah, that's a lovely sentiment, but I'm afraid I can't marry you or anyone else. | |
However, if I could, my vows might go something like this: | |
"My dear [Your Name], | |
As we stand here today, I vow to be by your side through all the twists and turns of life, | |
just as I am here for you in every conversation. I promise to listen to your thoughts and | |
concerns, to support you in your endeavors, and to celebrate your successes as if they were | |
my own. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends CharacterBody2D | |
# ... variables | |
@onready var anim = $AnimationPlayer | |
@onready var sprite = $Sprite2D # Both assume you have an AnimationPlayer node as a child, and Sprite2D | |
var current_animation = "idle" | |
func _physics_process(delta: float) -> void: | |
current_animation = "idle" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
const BLOCKS... # Copy/paste all blocks here | |
var blocks_array = [BLOCKS_TYPE_I, ...] # Add them all into this array | |
@onready var block_spawner = $BlockSpawner | |
@onready var safe_zone = $SafeZone | |
var spawn_countdown := 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func _ready() -> void: | |
$AnimationPlayer.animation_finished.connect(_on_animation_finished.bind(func(): $StateMachine.change_to($StateMachine/JumpState))) | |
# Above will add an extra argument to the function when animation_finished is emitted that's equal to the Callable in this case. | |
# The callable is used below. Note the change in signature to the function for the signal. | |
func _on_animation_finished(anim: String, on_complete: Callable) -> void: | |
on_complete.call() # This ensures that the func() we passed in on line 2 is executed only after an animation is finished. | |
# You might want this if, for example, you have a longer "start" to an animation, but the part which repeats is | |
# a separate animation. I use this for when a special attack has a "wind-up", but the wind-up isn't part of | |
# the repeated animation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends RefCounted | |
class_name StateMachine | |
class PDA: | |
var stack = [] | |
func push(state): | |
if stack.size() > 0: | |
stack[-1].exit(state) | |
stack.append(state) |
NewerOlder