Creating a queue of events

Grab your favourite IDE and tinker with the innards of game engines

Creating a queue of events

Postby Mapster on Wed Aug 15, 2012 10:45 pm

Hello Interlopers!

It's been a while since I have done any coding let alone been on here, so i thought i would ask if anyone knows how to create a queue for events to proceed in.

What i want to do is turn the game_string_text main trigger that is turning the main displaying string into a queue so when its triggered all at once it isn't going to mess up all the text since it would be used mainly as a kill count displayer and involves multiple uses at once.

So in other words, when the entity is asked to change a string, it is added to a queue of strings instead of changing the main string to avoid string overlapping.

Cheers,
Mapster
Image
User avatar
Mapster
Member
Member
 
Joined: Thu Mar 01, 2012 4:07 am

Re: Creating a queue of events

Postby WillSmith190 on Sat Aug 18, 2012 5:16 pm

Use CUtlVector with the template being string_t. When a new string is added, use the AddToTail method, which will add it to the end of the queue. When you want to get the first string, first check to make sure Count isnt zero, then just take the first item in the array using the [] operator. Then to remove it, use Remove(0). Example:

Code: Select all
CUtlVector<string_t> stringQueue;
stringQueue.AddToTail("String1");
stringQueue.AddToTail("String2");
stringQueue.AddToTail("String3");

//Gets "String1"
string_t string1 = stringQueue[0];
stringQueue.Remove(0);
//Gets "String2"
string_t string2 = stringQueue[0];
stringQueue.Remove(0);
//...


See what I'm getting at here? You can also change it around to make a stack, etc.
WillSmith190
Member
Member
 
Joined: Sun Aug 22, 2010 4:10 am

Return to Programming

Who is online

Users browsing this forum: No registered users