I come from a background mostly C#, Ruby, and then JavaScript. Please forgive me for the gdscript questions as I've tried to wrap my head around this but haven't gotten to the bottom of it.
When writing code I like to split it into concerns, such that I might have a TerrainPainter.gd
that I use somewhere in the form of the following or similar. Essentially trying to get complex logic out.
func _ready():
TerrainPainer.render(self)
But in gdscript I've run into it many many times where the editor complains of cyclic dependencies or loading errors. The game will run fine but I can't get the editor to stop complaining about me. A very quick example is I have a class called MapData
that basically has a lot of vars and nothing else. It doesn't extend anything, it doesn't load anything, it could basically be just a dictionary.
But I add class_name MapData
to the top of the file and many of my other files start complaining about a cyclic dependency when I use it. What am I doing wrong?
res://GameWorld/IslandMap/MapRenderer.gd:18 - Parse Error: Class 'MapData' could not be fully loaded (script error or cyclic dependency).
modules/gdscript/gdscript.cpp:580 - Method/Function Failed, returning: ERR_PARSE_ERROR
Another resource is loaded from path: res://GameWorld.gd (possible cyclic resource inclusion)
res://GameWorld.gd:7 - Parse Error: Class 'MapData' could not be fully loaded (script error or cyclic dependency).
modules/gdscript/gdscript.cpp:580 - Method/Function Failed, returning: ERR_PARSE_ERROR
I've mixed these up all over the place trying to figure out how to use them. Essentially should I be preferring preload
, should I use onready
.