Hello,

I'm trying to implement a simple linked list and I'm getting a "cyclic dependency" error. Though, it seems to work fine if I omit the pointer type (normally I try to type all my stuff where possible). Just wondering if it's just a parse-level error and gd script won't do anything funny down the line.

My node class is pretty simple:

    class_name DialogNode
    
    var speaker:int;
    var text:String;

    #var next:DialogNode; # it does not like this...
    var next; # but it seems fine with this
    
    func _init(inputSpeaker:int, inputText:String):
    	speaker = inputSpeaker;
    	text = inputText;
    	next = null;
    	
    func _to_string() -> String:
    	return "DialogNode -> "+ str(speaker) +" : " + text;

Its probably fine, I have worked around the “cyclic dependency” issue several times this way without any issues caused by the workaround, at least that I know of.

Right now, referencing the class_name within the script will cause cyclic reference issues. As a workaround, you can use Object or Reference as a type hint to get some kind of (weak) static typing; it's better than nothing.

8 days later

Ah, I see. Didn't know about the Reference type. Thanks.

2 years later