Using the .append() method on structs

I have the following code:
alias Component = fn() -> None

fn baseComponent(): pass

struct Entity():
var components: List[Component]

fn __init__(inout self):
self.components = List[Component]()

fn add(self, method: Component):
self.components.append(method)
alias Component = fn() -> None

fn baseComponent(): pass

struct Entity():
var components: List[Component]

fn __init__(inout self):
self.components = List[Component]()

fn add(self, method: Component):
self.components.append(method)
However, line 12 gives an error even though I think it should be valid. What is the proper syntax in this case?
5 Replies
sb
sb3mo ago
You may need to change the method signature to use to inout self Since you're modifying a field on self
banananas
banananasOP3mo ago
Same error sadly
sb
sb3mo ago
What error does it give?
banananas
banananasOP3mo ago
No description
banananas
banananasOP3mo ago
Actually i might have fixed it yeah idk i think the vsc was just acting up actually no i spelt inout wrong earlier but i've fixed it now
Want results from more Discord servers?
Add your server