making arrays as a buffer

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#

:smile: any help on this would be brilliant :slight_smile:

Look into Queue Queue Class (System.Collections) | Microsoft Learn

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 DialBuff = new Queue();

and

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

  • TotalInput++;*
  • }*
  • }*

its ok ive fixed it i added:

using System.Collections.Generic;

to the top of the script :smile:

ok now im having a problem :slight_smile:

i ahve this function:

	private void dialGate(int mode) {
		if (Active || dialActive) {return;}
		Debug.Log ("DG = true");
		dialActive = true;
		Debug.Log (mode);
		
		if (mode == 1) {
		Debug.Log ("DG = true2");
			do {
				NumInput++;
				chevron (true,""+NumInput+"");
				DialBuff.Dequeue();
			}
			while (keepDialing());
		}
		dialActive = false;		
	}

and when ever it is called this is what comes up in the consol:

InvalidOperationException: Operation is not valid due to the current state of the object
System.Collections.Generic.Queue`1[System.String].Peek ()
System.Collections.Generic.Queue`1[System.String].Dequeue ()
stargate.dialGate (Int32 mode) (at Assets/stargate.cs:179)
stargate.DestinationChanged () (at Assets/stargate.cs:211)

what is causing this? (apart from that the queue idea is going well:)

This error usually occurs when the queue is empty, do some checks.

I have checked but I am unable to see any thing within the queue as it will not let me peek into the values :confused:

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?

Doesn’t Debug.log(DialBuff) show if it empty or not?

it just returned this as an error

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

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!