What do you think could be a problem in this code? I'm really stumped.
Code: Select all
IGUIListBox* listBox;
int prevItemSelected;
STalkInfo tempInfo2;
//char* tempString = new char();
wchar_t tempWString[100];
std::string tempString;
//First find out which box element was previously selected
listBox = (IGUIListBox*)(irrGuiEnv->getRootGUIElement()->getElementFromId(301));
prevItemSelected = listBox->getSelected();
if(prevItemSelected != -1){
tempInfo2.level = sInfo[prevItemSelected].level+1; //level places this one as a child of the previously selected item
for(int i = 0; i<tempInfo2.level; i++){
tempString += " ";
}
tempString += "New Item";
mbstowcs(tempWString, tempString.c_str(), tempString.size()+1);
//tempWString = wcscat_s(tempWString, L"New Item");
listBox->addItem(tempWString); //add a placeholder to the list box for the new item
tempInfo2.number = 1;
for(int i = 0; i<sInfo.size(); i++){
if(sInfo[i].level == tempInfo2.level)
tempInfo2.number++; //set the number according to how many other elements there are already in this level
}
tempInfo2.prevSpeakerNum = sInfo[prevItemSelected].number;
tempInfo2.speakerId = !sInfo[prevItemSelected].speakerId;
//Convert the wchar_t version of the list box item's text to std::string stored in the sInfo struct
//tempString = new char(wcslen(listBox.getListItem(listBox.getSelected())) + 1);
//wcstombs( tempString , listBox.getListItem(listBox.getSelected()), wcslen(listBox.getListItem(listBox.getSelected())) );
tempInfo2.sStatement = "New Item";
//sInfo can now equal all the info on the newly created item
sInfo.push_back(tempInfo2);
}else{
cout<<"You didnt select a parent thread!"<<endl;
}
Code: Select all
struct STalkInfo{
int speakerId; ///0 for npc and 1 for player
int level;
int number;
int prevSpeakerNum;
std::string sStatement;
};
Code: Select all
array<STalkInfo> sInfo;