Calling methods from list indexes
When I try running
update
from here:
It returns this error:
ComponentList
is defined here:
BaseComponent
is defined here:
14 Replies
Mojo requires you to tell it which of the variant types it is
Here's the example from the API docs for an example:
Ah
seems a bit strange but i'll try it
Yeah, if I were to guess, the explicit call is for the strict typing and performance reasons
Congrats @capt_falamer, you just advanced to level 1!
That works fine, but what if you're using a Variant?
...[index][Variant[types...]]...
throws an erroryou'll need to have the
Variant[types...]
as one of the list of types in the original variant
That seems needlessly complicated but alright
It can be, depending on what you're trying to do you may not even need a variant
also brings up the same error
Congrats @banananas, you just advanced to level 3!
Think I may be missing what you are trying to do. On mobile right now and it will be a bit before I can write up working code. I think if you could explain the specific use case I might be able to better answer the root of your question
I'm making an ECS (or sort of ECS) and i'm calling the
update
method of every component in an entity by cycling through a components
list using a for
loop. I'm trying to get the i
index of components
but it needs a type as well, but every component is listed in a variant so you don't have to specify the types of components in each method of every entity
hopefully that was clear enoughthen what I first responded was what you were looking for. Here's a fleshed out example to clarify what I was trying to communicate
Unfortunately there is no shortcut currently to blanket apply a method by doing
list[x].common_method()
even if all the structs within the variant have the exact same method.Alright, thanks