Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Should I use an array, set up a queue or is there a better alternative?

Discussion in 'Scripting' started by VHSrewind, Aug 2, 2018.

  1. VHSrewind

    VHSrewind

    Joined:
    Aug 2, 2018
    Posts:
    3
    Game type- 2 players, kind of a modified fighting game.

    I am creating a kind of action bar. Players put the move they want to do into the bar. The bar is going to represent around 30 seconds with the actions you can take within that time being modified by the speed difference between the two players. The queue is real time with the current move being locked in but the other moves being able to be moved around. The moves will have a cast time and a recovery time.

    So the queue is constantly being moved forwards. The moves can be shifted around. They use precise times, rounded to the .01 though if I could make it more precise without increasing the resource taxes too much I would love that. The opponent can interrupt/change your queue. Overlaps are snapped in front of or back based on the center relative to the action already on the bar. This would sometimes force other moves backwards in the queue. There can be dead space between actions.

    I feel like the fact that things can be inserted into the middle of the queue defeats the purpose of the queue. So I don't think a queue is the answer. But for an array I feel like I would be stuck have an array the size of 30 seconds+all of the .01 seconds and it doesn't feel like it would be an object array. It would be more like a a start marker and end marker for each move. This would seem to pointless tax CPU resources to constantly move that array forward. I feel like there should already be a kind of gui version of this created I just haven't found.

    The closest existing game that I have encountered that has this system is one of final fantasy's battle systems. FFXI I think.
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    You could use an Ordered Dictionary with the key as time and the value as the chosen move. The next placed move will be the first key in the collection - i.e. the element at index zero.
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,186
    The natural data structure for what you're describing is a linked list. It's made for adding and removing elements at any point in the list.

    If you want something that's a bit more automatic, but also could be harder to manipulate, you could go with an ordered queue.

    EDIT: SNIPED
     
    Doug_B likes this.
  4. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Oops, sorry Baste. :)
     
  5. VHSrewind

    VHSrewind

    Joined:
    Aug 2, 2018
    Posts:
    3
    Thank you. This should work perfectly. I figured the solution existed and I just had not encountered it yet.
     
    Doug_B likes this.
  6. VHSrewind

    VHSrewind

    Joined:
    Aug 2, 2018
    Posts:
    3
    Still happy you posted. Thank you.