Hello!
I've continued to work on a text based RPG I've been making progress on just for practice. I've come up with this problem though that I have searched for everywhere, and can't seem to find an answer to:
Everything I have so far runs entirely smoothly. Once my program ends the main function, though, it gives an error that says 'Program has encountered an error and needs to close.'
Because there are no compiler errors or warnings, I'm not sure where to start looking to fix this issue. I've messed around a lot with some of the source code which I thought might be the culprit, but so far nothing has worked.
Here is my main function for reference:
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 27 28
|
int main() {
RgnList_t regions (MAX_REGIONS);
Player_t player;
// [[ PROGRAM EXECUTION ]]
load_game( ®ions[0] );
vector<string> currentactions = do_action( "move_1000", ®ions[0], &player );
size_t delimiter;
while ( currentactions[0] != "exit" ) {
for ( unsigned short i=0; i<currentactions.size(); i++ ) {
delimiter = currentactions[i].find( "_" );
if ( currentactions[i].substr(0, int(delimiter)) != "move" ) {
do_action( currentactions[i], ®ions[0], &player );
}
else {
currentactions = do_action( currentactions[i], ®ions[0], &player );
break;
}
} //FOR
} //WHILE
// Displays before error
cout << "Test!" << endl;
return 0;
}
|
do_action() returns a vector<string>, each string list being a set of actions which must be performed by do_action upon the next while iteration. 'currentactions' is reset when the final action has been performed. When vector<string> do_action()[0] is something other then "exit", the game runs very smoothly. Once I call "exit", though, it causes the main 'while' game loop to end. This causes the program to end, as it should, only with the error that I described above.
I'm not yet very experienced with C++, so I apologize if the information I've given is less then required or off the mark. If anyone has any ideas, I'll be happy to explain anything necessary in further detail.
Thanks in advance!
- Aaron