- Home /
What type of array should I use to handle a convoy?
I need to keep track of members in a convoy guided by the player, that can be destroyed or added to per game conditions. I was using a standard List, but that has proved inefficient as it is Linear, and if an object in the List goes Null, it can't adjust without a lot of extra code. However, to determine positions in the convoy I also want to use an Index. Can anyone offer suggestions?
I think you're stuck between a LinkedList and a list, each with their own drawbacks. How big will your convoy be, how often will you need to alter it, and how will you access it? Those will probably be what drives the decision, although if its small values it probably won't make a noticeable difference anyway. $$anonymous$$aintaining an index will involve some kind of insertion/remove logic however you do it I think :/
I was thinking of a LinkedList but I need to ensure that the player always remains in position 0, and enemies can target convoy members. At worst the array will hold just five objects - fairly small. It's also used for convoy members to track each other.
If you know the max size of the array, you can specify the size of the internal array when you initialise the the list. But I think you're worrying too much, to be honest. You time would probably be better spent worrying about something else. Or sleeping :)
Your answer
Follow this Question
Related Questions
How do I return the index of an array of sprites as an int? 1 Answer
How do I check a List[0], when it's nothing? 1 Answer
Find specific element when duplicates exist in list. 1 Answer
List gives "Array index is out of range" for no reason 2 Answers
How do I find a local variables index in a foreach loop? 1 Answer