This should give you some Ideas on how I go about it.
Keep in mind that the tokenizer that I am using out of the string lib is not the most efficient way of doing this. It is just what I used for simplicity in this example.
// the Include is here only because of how I am storing the strings.
#include "X0_I0_STRINGLIB"
// This is just how I am storing the strings in an array for the example.
// You can store them any way you want. the real trick here is placing the
// indice of for the array into a string so we can pull them out one at a time and only once.
const string sStringArray = "String one.~String Number 2.~The third string.~string 4.~Fifth string.~#6 . ~ 7 str ~8 in strings.~Ninth entry.~10th entry.~eleventh and last element";
// this is just the 1-11 indices defined outside of the function that uses it.
string sElements = "0001020304050607080910";
// function to get our random indice and remove it.
int GetAndRemoveRandomElementIdx()
{
//Figure out how many indice we have left.
int MaxNumIdx = GetStringLength(sElements)/2;
// generate the start location of the index into sElements
int nRnd = Random(MaxNumIdx)*2;
// get the index at that location.
int nStringIdx = StringToInt( GetSubString (sElements,nRnd,2));
//remove the index from the string.
sElements = GetStringLeft(sElements,nRnd) + GetStringRight(sElements,MaxNumIdx*2- nRnd-2);
//Return the index
return nStringIdx;
}
// Test code OnOpen chest.
void main()
{
// Speak out 9 of the 11 strings.
int x;
for (x=0;x<9;x++)
{
//Get random index and remove it.
int nIdx = GetAndRemoveRandomElementIdx();
// Speak the string selected.
SpeakString( GetTokenByPosition(sStringArray,"~",nIdx));
// Check elements array to make sure element is removed.
// SpeakString ( "Element "+ IntToString(nIdx) + " Selected. "
+"sElements is now " + sElements);
}
}
Here is the out put from the test run.
Barrel: String one.
Barrel: Element 0 Selected. sElements is now 01020304050607080910
Barrel: String Number 2.
Barrel: Element 1 Selected. sElements is now 020304050607080910
Barrel: 7 str
Barrel: Element 6 Selected. sElements is now 0203040507080910
Barrel: eleventh and last element
Barrel: Element 10 Selected. sElements is now 02030405070809
Barrel: Ninth entry.
Barrel: Element 8 Selected. sElements is now 020304050709
Barrel: Fifth string.
Barrel: Element 4 Selected. sElements is now 0203050709
Barrel: #6 .
Barrel: Element 5 Selected. sElements is now 02030709
Barrel: The third string.
Barrel: Element 2 Selected. sElements is now 030709
Barrel: string 4.
Barrel: Element 3 Selected. sElements is now 0709