Hello,
Usually I can find solutions to problems that seem to arise when I'm coding for this game, but I'm stumped on why this is happening..

So I found out how to get the text from the last line of the text box on this game, and I want to separate the player name and what they said and store them in different char arrays.

So I made multiple variances of what I think would work, but they all seem to make the same thing happen; they make the last thing that was said disappear! I'm thinking that I'm misunderstanding something so I'm hoping one of you guys could help me out on this.


Here is the source code:

struct PlayerAnswer{
const char* Player;
const char* Answer;
};

int GetLineCount()
{
DWORD* StageTextClassP = (DWORD*)StageTextClass;
int theLineCount = 0;
__asm{
mov ecx, StageTextClassP;
mov eax, 0x004015F0;
call eax;
mov theLineCount, eax;
}
return theLineCount;
}

char* GetLastText()
{
DWORD* StageTextClassP = (DWORD*)StageTextClass;
char* textLineText;
int lineCount = GetLineCount()-2;
textLineText = (char*)malloc(255);
__asm{
mov ecx, StageTextClassP;
mov eax, 0x0056EC10;
push lineCount;
call eax;
mov textLineText, eax;
}
return textLineText;
}


PlayerAnswer GetLastPlayerAnswer()
{
PlayerAnswer pAnswer;
if(string(GetLastText()).find(':') != string::npos)
{
char* plName = strtok(GetLastText(), ":");
char* plAnswer = strtok(NULL, "\0");
pAnswer.Player=plName;
pAnswer.Answer=plAnswer;
return pAnswer;
}
pAnswer.Answer="a";
pAnswer.Player="a";
return pAnswer;

}

Oh, and here's pictures on before and after what it looks like:

http://i37.tinypic.com/11lr3hw.jpg
http://i38.tinypic.com/rc91qw.jpg

Is it a problem with pointers or something? I'm soo confused :(

Looks like you have some Assembly code mixed in with the GetLineCount () and GetLastText () functions. I have no idea whether those functions are correct or not. In addition, I'm not familiar enough with Windows functions and DWORD, plus I have to relearn malloc every time I use it, which isn't often, so again, I can't comment on those two functions except to say that if there is not a good reason to use C and Assembly code, I would go with C++ code and use C++-strings rather than C-strings and use new rather than malloc .

I rewrote your GetText () function so I could use and try out the GetLastPlayerAnswer() function and as far as I can tell, it seems to work, at least if I understand correctly what it's supposed to do. Here is the program I tested:

#include <string>
#include <iostream>
#include <cstring>

using namespace std;

struct PlayerAnswer
{
    const char* Player;
    const char* Answer;
};


char* GetLastText()
{
      char* someText = new char[8];      
      strcpy  (someText, "Bob:Yes");      
      return someText;
}


PlayerAnswer GetLastPlayerAnswer()
{
    PlayerAnswer pAnswer;    
    
    if(string(GetLastText()).find(':') != string::npos)
    {
        char* plName = strtok(GetLastText(), ":");
        char* plAnswer = strtok(NULL, "\0");
        pAnswer.Player=plName;
        pAnswer.Answer=plAnswer;
        return pAnswer;
    }    
    
    pAnswer.Answer="a";
    pAnswer.Player="a";
    return pAnswer;
}


int main ()
{
    PlayerAnswer pa = GetLastPlayerAnswer ();
    cout << "player = " << pa.Player << endl;
    cout << "answer = " << pa.Answer << endl;

    return 0;
}

I think your best step is to really narrow down where exactly the problem is. Put some debugging statements in after the call to the GetLastText () function and make sure it is returning what you want it to. If not, put some debugging code in to make sure that the GetLineCount () function does what it is supposed to do. Once you narrow down the exact function where the problem is located, go from there. Like I said, your GetLastPlayerAnswer () function appears to work to me, or at least it did with my example.

ha silly me :P I forgot to point out that everything did work fine until i had made GetLastPlayerAnswer. Could it be because I'm directly working off of the char* returned? if so, how would I fix that? :(

ha silly me :P I forgot to point out that everything did work fine until i had made GetLastPlayerAnswer. Could it be because I'm directly working off of the char* returned? if so, how would I fix that? :(

Run the program I posted and see if that function works correctly. It should split the string "Bob:Yes" into "Bob" and "Yes" and put it into a PlayerName variable, which I thought was the goal. Does it do that for you? Is that what you are looking for? If "Bob:Yes" works and some other string doesn't, list that string that doesn't work.

Run the program I posted and see if that function works correctly. It should split the string "Bob:Yes" into "Bob" and "Yes" and put it into a PlayerName variable, which I thought was the goal. Does it do that for you? Is that what you are looking for? If "Bob:Yes" works and some other string doesn't, list that string that doesn't work.

Yes that's what it was supposed to do, but the problem I was having was this:

http://i37.tinypic.com/11lr3hw.jpg
http://i38.tinypic.com/rc91qw.jpg

You see how the text after the char name is removed? I want it to stay there.

Yes that's what it was supposed to do, but the problem I was having was this:

http://i37.tinypic.com/11lr3hw.jpg
http://i38.tinypic.com/rc91qw.jpg

You see how the text after the char name is removed? I want it to stay there.

Well, then my guess is that your problem is elsewhere, in code that you haven't posted. Note that this function:

PlayerAnswer GetLastPlayerAnswer()
{
    PlayerAnswer pAnswer;    
    
    if(string(GetLastText()).find(':') != string::npos)
    {
        char* plName = strtok(GetLastText(), ":");
        char* plAnswer = strtok(NULL, "\0");
        pAnswer.Player=plName;
        pAnswer.Answer=plAnswer;
        return pAnswer;
    }    
    
    pAnswer.Answer="a";
    pAnswer.Player="a";
    return pAnswer;
}

doesn't display anything anywhere; it merely splits the string in two. So somewhere after the call to this function, if you want to actually display the two broken strings, you have to do so by appending it to the text box or however you do it. But it appears that GetLastPlayerAnswer () is not intended to display anything. It merely breaks the string in two and it appears to be working. If it's also supposed to append the text to the text box, you'll have to add that part.

This question has already been answered. Start a new discussion instead.