Thanks a lot for that advice, I have made the code changes and am going to use push_back to add items into the vector list, I am still stuck at the moment as to why when I find a player in the vector, that I can not use "printf" to print the information that I am trying to show at the console. The guid still comes back as null and the id shows some wierd huge number like I show in my video that I have linked in the original question.
I like your idea for the self initialization and being new at C++, I wasn't sure how to self initialize the structure so this is very helpfull information.
Do you have any advice as to why printf would return null for the string when the guid clearly has a value and can be seen in debug? Is there something I am missing?
Thank you very much again for your help, it is truely appreciated.
Here is what I now have, I switched up the vector instansiate as follows given your instruction:
1 2 3 4 5 6 7 8 9 10 11 12
|
struct PlayerSlot
{
size_t id;
string guid;
string address;
SystemAddress systemaddress;
PlayerSlot()
: id(0), guid(), address(), systemaddress(UNASSIGNED_SYSTEM_ADDRESS)
{}
};
vector<PlayerSlot> PlayerSlots;
|
Now I have the PlayerSlots holding nothing until something is pushed onto the stack, here is that code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
// look to see if the player is already in the list, if not add them
for(size_t i=0;i<PlayerSlots.size();i++)
{
if(PlayerSlots[i].guid==p->guid.ToString() && !found)
{
slotInfo = &PlayerSlots[i];
tmpstr = slotInfo->guid;
// CORRECTLY SHOWS INFO
std::cout << "Found Player GUID: " << slotInfo->guid << std::endl << "Position: " << i << std::endl << std::endl;
// INCORRECTLY SHOWS INFO, tmpstr does have the guid but printf shows null
// i has a value of 0 but shows 127
printf("Found: %s At Position: %d \n",tmpstr,i);
found=true;
i=PlayerSlots.size()-1;
}
}
// push the player onto the stack at the end
if(!found)
{
newPlayer.address=p->systemAddress.ToString(true);
newPlayer.guid=p->guid.ToString();
newPlayer.id=PlayerSlots.size()+1;
newPlayer.systemaddress=p->systemAddress;
PlayerSlots.push_back(newPlayer);
}
|
As noted in the code, printf is still not displaying correct information, just junk. If I use cout, I get the right values on the console, still boggles my mind as to why.