Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

making arrays as a buffer

Discussion in 'Scripting' started by carbondudeoxide, Mar 25, 2013.

  1. carbondudeoxide

    carbondudeoxide

    Joined:
    Mar 24, 2013
    Posts:
    21
    hello, i am making a model that has an input string which will have a value similar to "1,2,3,4,5,6,7,!" but each number will be added in one by one with the comma.

    i would also like these numbers as they are entered into this value called 'Destination' to be inserted into an array to act like a buffer.

    while it is doing this a co routine will read the first value in the buffer (Destination needed to be split with the comma being the delimeter) rotate an object acordingly run a custom function and then remove the first value from the array. this will repeat untill the buffer array is empty or untill the character "!" i the first value in the buffer.

    how would i go about:

    making an empty array called buffer, adding values into the end of the buffer, reading the first value in the buffer and then removing it bumping the other values up in the array?

    i am currently making the script in c#

    :D any help on this would be brilliant :)
     
  2. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
  3. carbondudeoxide

    carbondudeoxide

    Joined:
    Mar 24, 2013
    Posts:
    21
    The non-generic type `System.Collections.Queue' cannot be used with the type arguments

    this is the error it returned after i tried using this:

    Queue<string> DialBuff = new Queue<string>();

    and

    for(int i = 0; i < (t.Length + 1); i++) {
    if (i > TotalInput) {
    DialBuff.Enqueue(t);
    TotalInput++;
    }
    }
     
  4. carbondudeoxide

    carbondudeoxide

    Joined:
    Mar 24, 2013
    Posts:
    21
    its ok ive fixed it i added:

    Code (csharp):
    1.  
    2. using System.Collections.Generic;
    to the top of the script :D
     
  5. carbondudeoxide

    carbondudeoxide

    Joined:
    Mar 24, 2013
    Posts:
    21
    ok now im having a problem :)

    i ahve this function:
    Code (csharp):
    1.     private void dialGate(int mode) {
    2.         if (Active || dialActive) {return;}
    3.         Debug.Log ("DG = true");
    4.         dialActive = true;
    5.         Debug.Log (mode);
    6.        
    7.         if (mode == 1) {
    8.         Debug.Log ("DG = true2");
    9.             do {
    10.                 NumInput++;
    11.                 chevron (true,""+NumInput+"");
    12.                 DialBuff.Dequeue();
    13.             }
    14.             while (keepDialing());
    15.         }
    16.         dialActive = false;    
    17.     }
    and when ever it is called this is what comes up in the consol:

    Code (csharp):
    1. InvalidOperationException: Operation is not valid due to the current state of the object
    2. System.Collections.Generic.Queue`1[System.String].Peek ()
    3. System.Collections.Generic.Queue`1[System.String].Dequeue ()
    4. stargate.dialGate (Int32 mode) (at Assets/stargate.cs:179)
    5. stargate.DestinationChanged () (at Assets/stargate.cs:211)
    what is causing this? (apart from that the queue idea is going well:)
     
  6. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    This error usually occurs when the queue is empty, do some checks.
     
  7. carbondudeoxide

    carbondudeoxide

    Joined:
    Mar 24, 2013
    Posts:
    21
    I have checked but I am unable to see any thing within the queue as it will not let me peek into the values :/

    I am unsure whether or not it is enqueing the values into the queue as I don't know how to look inside the queue...

    how can I figure it out?
     
  8. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    Doesn't Debug.log(DialBuff) show if it empty or not?
     
  9. carbondudeoxide

    carbondudeoxide

    Joined:
    Mar 24, 2013
    Posts:
    21
    it just returned this as an error

    Code (csharp):
    1. InvalidOperationException: Operation is not valid due to the current state of the object
    2. System.Collections.Generic.Queue`1[System.String].Peek ()
    3. System.Collections.Generic.Queue`1[System.String].Dequeue ()
    4. stargate.dialGate (Int32 mode) (at Assets/stargate.cs:175)
    5. stargate.DestinationChanged () (at Assets/stargate.cs:208)
     
  10. tfunk

    tfunk

    Joined:
    Jul 31, 2014
    Posts:
    2
    I am facing a similar problem, at the moment. The code seems to be working properly, but I can't seem to stop this error. With some Debug.Log commands I've determined that the Queue is both non-null and non-empty, but the error continues nontheless.

    If anyone ever figured this out, please reply!