Last active
October 26, 2015 11:33
-
-
Save TutorialDoctor/ce9255f16a49d8d911bb to your computer and use it in GitHub Desktop.
Syntax of the Godotscript language
This file contains hidden or 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 | |
# Godot Script Syntax | |
# By the Tutorial Doctor | |
# Fri Oct 2 23:58:22 EDT 2015 | |
#----------------------------------------------------------- | |
# VARIABLES | DATA TYPES | | |
#----------------------------------------------------------- | |
# String | |
var name = "Tutorial Dcotor" | |
# Integer | |
var age = 29 | |
# Float | |
var height = 6.1 | |
# Array | |
var friends = ['Albert','Bobby','Cynthia','Donny'] | |
# Dictionary | |
var favorites = {'number':4,'food':'fish'} | |
# Boolean | |
var cool = true | |
# Exporting Variables | |
export var gameName = "CoderDojo Game" | |
# Exports the variable to the Inpspector for easy editing | |
#----------------------------------------------------------- | |
#----------------------------------------------------------- | |
# FUNCTIONS | CONDITIONALS | | |
#----------------------------------------------------------- | |
func getInfo(): | |
print() | |
print('Returning your info...') | |
return name + ' ' + str(age) + ' ' + str(height) # Concatenation and typecasting | |
func checkCoolness(): | |
if cool: | |
print('You are cool') | |
else: | |
print('You are not cool') | |
#----------------------------------------------------------- | |
#----------------------------------------------------------- | |
# GAME FUNCTIONS | LOOPS | | |
#----------------------------------------------------------- | |
# For and While loops can be used inside of the _ready() function. | |
# Don't use For and While loops in the "Game Loop" (the _process() function). | |
# This includes using them in your own functions that will be called under the game loop. | |
# The Setup Function | |
#----------------------------------------------------------- | |
func _ready(): | |
set_process(true) | |
set_fixed_process(true) | |
print(getInfo()) | |
print(friends[2]) | |
print(favorites['number']) | |
checkCoolness() | |
# For Loop | |
for friend in friends: | |
print(friend) | |
# While Loop | |
var i = 0 | |
while i < 5: | |
print('Hello Developer') | |
i+=1 | |
# The Game Loop | |
#----------------------------------------------------------- | |
# A game loop is a function that repeats code at a standard rate. For games this is ideally 60 frames a second. | |
# Code within this loop runs every game frame. | |
func _process(delta): | |
pass | |
#----------------------------------------------------------- | |
# The Physics Loop | |
#----------------------------------------------------------- | |
# The physics loop repeats code every physics frame. Updates to phyics are done here. | |
func _fixed_process(delta): | |
pass | |
#----------------------------------------------------------- | |
#----------------------------------------------------------- | |
# CLASSES | OBJECTS | | |
#----------------------------------------------------------- | |
# Every node is an object | |
# The 'extends' statement extends a class and effectively makes the current script a subclass of the extended class. | |
# Member variables are declared outside of the _ready(), _process() and _fixed_process() functions. | |
# All functions you create in this script become class functions (methods). | |
# Simply put, the 'extends' statement extends the functionality of the class being extended. It let's you add more features! | |
# The variables at the top of this script are memeber variables | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment