07-07-2012, 04:59 AM
So, in the custom story that I'm creating, I name things I need to interact with in the code quite precisely. Usually it takes the form of: ROOMNAME_ITEMNAME_TYPE
So for example, a note might be labled: lab_chemDiscovery_note
I wanted an easy function to extract the middle word, in the above case this would be "chemDiscovery". However, whenever the function is called, the game just locks up. Can anyone see what I might be doing wrong?
I'm thinking I should be able to call this function as:
or even through passing a callback variable to it (the intention).
So for example, a note might be labled: lab_chemDiscovery_note
I wanted an easy function to extract the middle word, in the above case this would be "chemDiscovery". However, whenever the function is called, the game just locks up. Can anyone see what I might be doing wrong?
PHP Code:
string getProperName(string &in var){
int chr = 0; //character number in string
string newString = ""; //where the new string will be stored
string letter = ""; //where the current letter being tested is stored
int l = 0; //how many underscores we've found
while(l < 2){ //we can stop evaluating after finding 2 underscores
//using StringSub(string,int,int) to return a partial string between two positions in the string.
letter = StringSub(var, chr, chr+1);
AddDebugMessage("Analyzing Letter: " + letter,false);
//Only append a letter to the new string if its not an underscore and we've already found an underscore.
if ((letter != "_") && (l == 1)){newString = newString + letter;}
//increase underscore count when finding one
else if (letter == "_"){l++;}
//increase character count
chr++;
AddDebugMessage("New String: " + newString,false);
}
return newString;
}
I'm thinking I should be able to call this function as:
PHP Code:
getProperName("lab_chemDiscovery_note");
