C for GDScript Developers
Move from GDScript to C17: explicit types, pointers, bounded arrays, strings, ownership, structs and modular interfaces. Build a multi-file stock ledger and port two GDScript programs.
GDScript and C side by side
The same program in GDScript and in C, from the lessons of this course.
Printing and Comments
GDScript print converts every argument to text with str(), joins the pieces with no separator and ends the line for you. C printf uses a format string whose conversion specifiers must match argument types; %d prints an int. GDScript comments start with #…
GDScript1extends Node2 3func _ready() -> void:4 # print joins its arguments with no separator5 print("value=", 7)C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10printf("value=%d\n",7);11return 0;12}Booleans and Branches
A GDScript condition converts any Variant to a truth value: 0, 0.0, null, an empty String, an empty Array and an empty Dictionary are all false. In C a scalar zero is false and a nonzero scalar is true; a non-null pointer is true even if it points at an empty…
GDScript1extends Node2 3func _ready() -> void:4 var s: String = ""5 print("true" if s else "false")C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10const char *s=""; printf("%s\n",s?"true":"false");11return 0;12}Arrays Need Lengths
A GDScript Array or PackedInt32Array carries its length, and a function that receives one can still call size(). A C array has a fixed element count, but a function array parameter is adjusted to a pointer and does not carry that count. Pass size_t length…
GDScript1extends Node2 3func _ready() -> void:4 var a := [2, 4, 6]5 print(a.size())C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10int a[]={2,4,6};printf("%zu\n",sizeof a/sizeof a[0]);11return 0;12}Function Arguments Are Values
GDScript passes int, float, bool, String and Vector2 by value and Array, Dictionary and objects by reference, but in both cases assigning to a parameter only rebinds the local name. C parameters always receive copies of their values. Changing an int parameter…
GDScript1extends Node2 3func change(n: int) -> void:4 n = 95 6func _ready():7 var x := 28 change(x)9 print(x)C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8static void change(int n){n=9;(void)n;}9int main(void) {10int x=2;change(x);printf("%d\n",x);11return 0;12}Addresses and Dereferencing
GDScript shares Array, Dictionary and object instances by reference without exposing addresses, and gives no way to reference an int variable at all. In C &object obtains an address and *pointer accesses the pointed-to object, even a local int. Dereference…
GDScript1extends Node2 3func _ready():4 var box := [2]5 var alias := box6 alias[0] = 57 print(box[0])C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10int n=2;int *p=&n;*p=5;printf("%d\n",n);11return 0;12}Parsing with Status Results
GDScript's to_int() does not reject bad text: it keeps the digits it finds, so "12x".to_int() is 12, and is_valid_int() is the check on the whole text. C library parsers use explicit status information. sscanf reports the number of successful assignments, but…
GDScript1extends Node2 3func _ready():4 var text := "12x"5 print(text.is_valid_int())C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10const char *s="12x";int ok=*s!=0;for(size_t i=0;s[i];i++)if(s[i]<'0'||s[i]>'9')ok=0;printf("%d\n",ok);11return 0;12}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsCompile and Compute
6 lessonsDecisions and Loops
5 lessonsArrays and Text
5 lessonsFunctions and Interfaces
5 lessonsPointers and Structs
5 lessonsValidation and Text Buffers
5 lessonsOwned Dynamic Memory
5 lessonsTagged Data and Composition
6 lessonsProject: Stock Ledger
4 lessonsFinal GDScript Ports
2 lessonsFrequently asked questions
Who is C for GDScript Developers for?
For people who already write GDScript and want to learn C. Each lesson starts from GDScript you know and shows how C does the same thing, so you skip the beginner basics.
Do I need to know C already?
No. The course starts with your first C program. You need GDScript basics: variables, conditions, loops, functions and collections.
How many lessons does C for GDScript Developers have?
C for GDScript Developers contains 48 interactive lessons you can complete at your own pace.
What does C for GDScript Developers cover?
The course is organized into chapters covering: Compile and Compute, Decisions and Loops, Arrays and Text, Functions and Interfaces, and more.
Is C for GDScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.