Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Y_VRN |
I have several scripts as classes (class_name), and all but two (Render_Card and Card_Formatter) keep bothering me with a non-existent “cyclic dependency” or “script error”. Code works as expected, so there can’t be any problem, yet I get the message anyways.
Reloading the project temporarily relieves me of this, but then they will start yelping at me again at some point. When I add comments before the values of the class variables, all but one custom class (Font_Shorts, not really relevant) triggers the message in that one script. Even if I clear everything but the variables that contain dependencies, it still won’t go away.
I’ve searched for a while, only to be led to questions that are not related to my problem. I was only able to find one, yet there was no definite answer.
Is this a bug, or is there a way I can prevent this? I’ll provide some code:
Render Card.gd:
class_name Render_Card extends Panel
# These three are the problematic lines I have to deal with. Font_Shorts is fine.
var Card_Types = Modular_Card.Stack_Type
var Card : Modular_Card
var ECC = Easy_Coordinates_Control.new()
var F_S = Font_Shorts.new()
var Connections = {}
var Rendered_Stacks = {}
var Context = "MODULAR_CARD"
func _Process_Render_Card_Properties(Stack):
var Stack_Container = VBoxContainer.new()
Stack_Container.rect_min_size = Vector2(200, 60)
match Stack.TYPE:
1, 2, 5, 6:
var Stack_Title_Label = Label.new()
Stack_Title_Label.text = Stack.get("TITLE") if Stack.get("TITLE") else ""
Stack_Title_Label.rect_min_size = Vector2(0, 16)
Stack_Title_Label.add_font_override("font", F_S.Fonts.Card.Title)
ECC.Unset_Offset(Stack_Title_Label) # Resets size to literally 0 on both axes.
ECC.Anchor(Stack_Title_Label, 0, 1) # Utilizes anchor instead. Min size helps here too.
Stack_Container.add_child(Stack_Title_Label)
match Stack.TYPE:
2, 5, 6:
var Stack_Description_Label = Label.new()
Stack_Description_Label.text = Stack.get("DESCRIPTION") if Stack.get("DESCRIPTION") else ""
Stack_Description_Label.add_font_override("font", F_S.Fonts.Card.Description)
ECC.Unset_Offset(Stack_Description_Label)
ECC.Anchor(Stack_Description_Label, null, 1, null, 1)
ECC.Offset(Stack_Description_Label, 0, 0, 16, 0)
Stack_Container.add_child(Stack_Description_Label)
if Stack.TYPE == 5:
pass
elif Stack.TYPE == 6:
pass
return Stack_Container
func Update_Contents():
var Y_Offset = 0
if Card != null:
for Stack in Card.Contents:
if not Rendered_Stacks.get(Stack):
var New_Render_Stack = _Process_Render_Card_Properties(Stack)
New_Render_Stack.set_position(New_Render_Stack.get_position() + Vector2(0, Y_Offset))
Y_Offset += New_Render_Stack.rect_size.y
add_child(New_Render_Stack)
Rendered_Stacks[Stack] = New_Render_Stack
func Attach():
if Card:
Card.connect("Inserted", Update_Contents)
Card.connect("Retracted", Update_Contents)
func Detach():
if Card:
Card.disconnect("Inserted", Update_Contents)
Card.disconnect("Retracted", Update_Contents)
func _init():
rect_min_size = Vector2(200, 100)
func _ready():
Update_Contents()
Card_Formatter.gd:
class_name Card_Formatter
var Formats = {}
func _Copy_Over(T1 : Dictionary, T2 : Dictionary, Index_Name : PoolStringArray):
for Index in Index_Name:
if T1[Index]:
T2[Index] = T1[Index]
# Creates a stripped-down version of the given card. Titles are preserved (including titles in
# other stack types).
#
# If All param is set, all properties will retain their values, as if a card was duplicated.
func Extract_Format_From_Card(Card : Modular_Card, Name : String, All : bool = false):
# Error in the param (Card : Modular_Card)
if not Name:
return {message = "Name is required."}
var Format = []
if not All:
for Index in Card.Contents.size():
var Value = Card.Contents[Index]
var Type = Value.TYPE
var Stack_Format = {}
Stack_Format.TYPE = Type
match Type:
-1, 0:
pass
1, 2, 6:
_Copy_Over(Value, Stack_Format, PoolStringArray(["TITLE"]))
5:
_Copy_Over(Value, Stack_Format, PoolStringArray(["TITLE", "NOTICE"]))
Format.append(Stack_Format)
else:
Format = [Card.Contents.duplicate(true)]
Formats[Name] = Format
return Format
func Create_Blank_Card_From_Format(Name : String):
if not Formats.has(Name):
return {message = "Format \"" + Name + "\" "}
var Format : Array = Formats[Name]
var New_Card = Modular_Card.new()
for Stack in Format:
Stack = Stack as Dictionary
var Message = New_Card.Insert(Stack.TYPE, Stack)
if Message is Dictionary:
printerr(Message.message)
return New_Card
The false error only seems to appear for custom classes “Easy_Coordinates_Control” and “Modular_Card”. Checking either script, the error does not appear, or had any dependencies to “Render_Card” or “Card_Formatter”.
Apologies if this is unclear, I wrote this past midnight and I’m exhausted. Thanks in advance.