mirror of
https://github.com/catppuccin/catppuccin
synced 2024-11-24 20:43:05 +00:00
83 lines
No EOL
1.4 KiB
GDScript
83 lines
No EOL
1.4 KiB
GDScript
# 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) |