I want to store data using custom classes. I found this forum entry: https://godotengine.org/qa/90341/custom-classes
The code it includes to create a custom class is this:
class My_Class:
var a: int
var b: String
var c: float
func _init(a, b, c):
self.a = a
self.b = b
self.c = c
(I made some changes because the Godot editor was angry with me, I think Godot 4 changed some things)
This code seems to work, or at least it doesn't throw an error when running the game.
However, once I try to create an instance of it:
var a = My_Class.new(1, 'Test', 1.23)
print(a)
I get the error: Unexpected "Identifier" in class body
I am not quite sure what the problem is and when I look for classes in the docs I end up with lots of info on nodes and classes.
I suppose the important question is what is wrong with the code and the other question is whether something like this is the proper way to use Godot. Ultimately, I want to create a list of cities and store all of that in a dictionary, like so:
var cities = {
'Town A': City(pos, population, production),
'Town B': City(pos, population, production),
}