ref.godot - jgrey4296/jgrey4296.github.io GitHub Wiki
- _enter_tree
- _exit_tree
- _ready
- _process
- _physics_process
- _unhandled_input
- _input
# Everything after "#" is a comment.
# A file is a class!
# (optional) icon to show in the editor dialogs:
@icon("res://path/to/optional/icon.svg")
# (optional) class definition:
class_name MyClass
# Inheritance:
extends BaseClass
# Member variables.
var a = 5
var s = "Hello"
var arr = [1, 2, 3]
var dict = {"key": "value", 2: 3}
var other_dict = {key = "value", other_key = 2}
var typed_var: int
var inferred_type := "String"
# Constants.
const ANSWER = 42
const THE_NAME = "Charly"
# Enums.
enum {UNIT_NEUTRAL, UNIT_ENEMY, UNIT_ALLY}
enum Named {THING_1, THING_2, ANOTHER_THING = -1}
# Built-in vector types.
var v2 = Vector2(1, 2)
var v3 = Vector3(1, 2, 3)
# Functions.
func some_function(param1, param2, param3):
const local_const = 5
if param1 < local_const:
print(param1)
elif param2 > 5:
print(param2)
else:
print("Fail!")
for i in range(20):
print(i)
while param2 != 0:
param2 -= 1
match param3:
3:
print("param3 is 3!")
_:
print("param3 is not 3!")
var local_var = param1 + 3
return local_var
# Functions override functions with the same name on the base/super class.
# If you still want to call them, use "super":
func something(p1, p2):
super(p1, p2)
# It's also possible to call another function in the super class:
func other_something(p1, p2):
super.something(p1, p2)
# Inner class
class Something:
var a = 10
# Constructor
func _init():
print("Constructed!")
var lv = Something.new()
print(lv.a)
Defined in gdscript_tokenizer.cpp.
- abstract
- as
- and
- assert
- await
- break
- breakpoint
- class
- class_name
- const
- continue
- elif
- else
- enum
- extends
- for
- func
- if
- in
- is
- match
- namespace
- not
- or
- pass
- preload
- return
- self
- signal
- static
- super
- trait
- var
- void
- while
- when
- yield
- INF
- NAN
- PI
- TAU
Left Associative.
- ( )
- x[index]
- x.attribute
- foo()
- await x
- x is [not] Node
- x is Node
- x ** y
- ~x
- +x
- -x
- x * y
- x / y : defaults to integer, not fractional
- x % y
- x + y
- x - y
- x [<<, >>] y
- x [&, ^, |] y
- x [==, !=, <, >, <=, >=] y
- x [not] in y
- not x
- x [and, or] y
- [expr] if [cond] else [expr]
- x as Node
- x [+, -, *, /, %, &, |, ^]= y
- x [<<, >>]= y
- null
- false, true
- 45
- 0x8f51 : hex
- 0b101010 : binary
- 3.14, 58.1e-10 # floats
- “strings”, r”strings”
- ””“strings”“”, r”“”strings”“”
- &”name” : string name
- ^”node/label” : nodepath
- $NodePath -> get_node(“NodePath”)
- %UniqueNode -> get_node(“%UniqueNode”)
\{} : [ntrabfv”’\] \uXXXX : UTF-16 code point \UXXXXXX : UTF-32 code point
To interact with engine/editor
@export_range(1, 100)
var ranged : int = 50
var adict = {
first = "blah",
second = 3,
third = [1,2,3],
}
# 'self' is always available
func example(a:int,b:str, c:="blah") -> bool:
return false
var exfn : Callable = example
example(2,"bloo")
exfn.call(2, "bloo")
var a_lambda : Callable = func(x): print(x)
var b_lambda : Callable = func(x): return x + 2
a_lambda.call(2)
static func blah() -> void:
print("blah")
func a_coroutine():
print("blah")
# Waits until the signal is emitted:
await $ANode.a_signal
return true
# Somewhere else:
var result = await a_coroutine()
# will error:
var other = a_coroutine()
# not needing the result does need await:
a_coroutine()
var myvar : int = 2
# Or declared + initialized:
var my_vec := Vector2()
# Belongs to class, not instance:
static var blah : int = 5
# Constants
const name : str = "blah"
var myvar : int = 2
var example : int :
get:
return -myvar
set(value):
myvar = -value
var mynode: Node2D
mynode = $Sprite2D as Node2D
# results in 'null' if it fails
class_name Blah
extends Node
# extends "res://path/to/something.gd"
func _init():
pass
class MyClass:
var example : int = 1
class Sub extends MyClass:
pass
enum {FIRST, SECOND, THIRD}
enum MyEnum {a, b, c}
FIRST
MyEnum.a
if (false):
pass
elif (true):
pass
else:
pass
while (false):
# continue
# break
pass
for x:int in [1,2,3,4]:
pass
var d = {"a":2,"b":3}
for x:str in d:
print(d[x])
for x:int in range(1,5):
pass
var myval : int = 5
match myval:
5:
pass
4,3:
pass
var x when x > 2:
pass
[]:
pass
[1,2,3]:
pass
[var x, var y]:
pass
{"name":"blah"}:
pass
_:
print("default")
var i : int = 4
assert(i == 0, "val was not zero")
- Variant : equivalent to Any
- void : a return type
- StringName
- NodePath
- Vector2
- Vector2i
- Rec2
- Vector3
- Vector3i
- Transform2d
- Plane
- Quaternion
- AABB
- Basic
- Transform3d
- Color
- RID, Resource ID
- Object
- Array
- Packed Arrays
- Signal
- Callable
- WeakRef
- Resource
- @onready
- @static_unload : must be at very top of script
- @tool : to run scripts inside the editor
- @deprecated
- @experimental
- @export_group(“group name”)
- @export_category(“name”)
- @export
- @export_range
- @export_exp_easing
- @export_color_no_alpha
- @export_flags
- @export_flags_2d_physics
- @export_flags_2d_render
- @export_flags_2d_navigation
- @export_flags_3d_physics
- @export_flags_3d_render
- @export_flags_3d_navigation
- @export_storage
- @export_custom
- @export_tool_button
- @export_file
- @export_dir
- @export_global_file
- @export_multiline
- typeof(x)
free($aNode)
queue_free($aNode)
# An observer callback, in aNode:
signal my_signal(val)
# Somewhere else:
func my_fun(val):
pass
$aNode.my_signal.connect(my_fun)
# Back in aNode:
my_signal.emit(2)
- null initialization
- top to bottom, normal values
- _init()
- exported values assigned
- @onready
- _ready()
- https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/index.html
- https://gdscript.com/
- https://gdscript.com/solutions/
- https://github.com/francogarcia/company-godot-gdscript.el
- https://github.com/francogarcia/yasnippet-godot-gdscript
- https://github.com/godotengine/emacs-gdscript-mode
- https://kidscancode.org/godot_recipes/3.x/recent/
- http://www.shardcore.org/shardpress/2014/06/05/waiting-for-godot/
- https://docs.godotengine.org/en/latest/contributing/development/core_and_modules/internal_rendering_architecture.html
- https://github.com/Jamesong7822/Godot-Notes/blob/master/Godot%20Notes.md
- https://godotengine.org/article/importing-3d-assets-blender-gamedevtv
- https://godotengine.org/asset-library/asset
- https://godotengine.org/asset-library/asset/1745
- https://godotshaders.com/
- https://godottutorials.com/courses/godot-basics-series
- https://kidscancode.org/godot_recipes/3.x/recent/
- https://medium.com/@JustAnotherRandomGuy/writing-tests-in-godot-a9a5ed279b2c
- https://new.pythonforengineers.com/blog/godot-tips-n-tricks-n-gotchas/
- https://nightblade9.github.io/godot-gamedev/2019/getting-started-with-unit-and-integration-testing-in-godot.html
- https://tomeyro.itch.io/godot-sfxr
- https://www.gdquest.com/tutorial/godot/learning-paths/developer/
- https://toxigon.com/advanced-gdscript-techniques-for-game-developers