

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 10
click for more info
Not enough gems
Cost: 6 gems
1: SnekObjects
incomplete
2: Integer
incomplete
3: Float
incomplete
4: String
incomplete
5: Vector3
incomplete
6: Array
incomplete
7: Set
incomplete
8: Get
incomplete
9: Length
incomplete
10: Add
incomplete
This lesson's interactive features are locked, please to keep using them
If you're familiar with Python, you'll be familiar with how Python objects can have an __add__ method. It allows developers to specify custom logic for different types of objects. For example, adding two integers we want to behave like this:
3 + 5
# 8
But with an array, we probably want it to work like this:
[3] + [5]
# [3, 5]
This is the final lesson on objects, and it's a big one. Take your time – you'll be using a lot of the functions that you wrote in past chapters to complete this one.
Complete the snek_add function. It accepts two pointers to snek_object_t objects ("a" and "b") and returns a pointer to a new snek_object_t object (the result of the sum):
We won't implement subtract, multiply, or divide but each of these would follow the same pattern. This is how arithmetic operations work in Sneklang!