MUD Game Programming By Ron Penton

Started by
16 comments, last by odious 19 years, 11 months ago
Has anyone used this book at all? I am compiling his C++ work space with VS c++ 6.0 and I have double checked everything is linked correctly and all include paths are made. But for some reason when I run the compilation I get a garbage return when dealing with the game''s Items. It is using python to store commands and such which are dynamically loaded, I have verified the calls to python are indeed being made but the return is not what it should be. Everything is as it was right off the CD and according to his instructions in the book. All other commands loaded from the same python object work fine aslong as they are not dealing with items it seems. I have ran step by step through debug and cant find any problems. My compilation is also around 100+k more than his exe that he includes pre compiled supposedly from the same workspace. His exe works fine with everything so I know its not an external file or anything like that is has to be a problem with how c++ is handling the python objects in the source he provided or something. Well if anyone has played with his source or has any idea of where I should look let me know please.
Advertisement
Just to be more specific on what I meant by garbage return when dealing with items. I mean I can compile no errors and run the program, but on the compilation when you connect into the game and you interact with items in the game such as "get item" it throws its an exception when it trys to run the returned argument from the python object. His exe does not do this you can actually pick stuff up using the same python files and data files nothing externally is changed to make his work or mine not.
What exception? Do you have a traceback?

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

void Game::DoCommand(
entityid p_player, // player doing command
const std::string& p_command ) // command being executed
{
// get the player
Character& c = CharacterDB.get( p_player );

std::string full = p_command;

// handle "repeating commands" here
if( full == "/" )
full = c.LastCommand(); // repeat last command
else
c.SetLastCommand( full ); // set last command

// get the first word "the command"
std::string command = BasicLib:arseWord( full, 0 );

// get the "the arguments"
std::string args = BasicLib::RemoveWord( full, 0 );


// in loud mode, commands must be prefixed with "/", everything else is
// local talking
// in quiet mode, what you say must be a command
//if( !c.Quiet() && command[0] != ''/'' )
//{
// DoAction( "attemptsay", p_player, 0, 0, 0, full );
// return;
//}


if(command=="say")
{
DoAction( "attemptsay", p_player, 0, 0, 0, full );
return;
}


// if a string starts with ''/'', it is always assumed to be a command,
// so erase the slash
if( command[0] == ''/'' )
command.erase( 0, 1 );

// the next part must be inside a try block in case anything fails, you
// don''t want to bring down the whole game
try
{
// try to find the command:
Character::commands::iterator itr = c.FindCommand( command );
if( itr == c.CommandsEnd() )
{
c.DoAction( "error", 0, 0, 0, 0, "Unrecognized Command: " + command );
return;
}

// try executing the command:
(*itr)->Execute( args );
}
catch( ... )
{
c.DoAction( "error", 0, 0, 0, 0, "SERIOUS ERROR: Cannot execute " + command +
", please tell your administrator" );
}
}

that is the function that is attempting to execute the command it gets from python when it finds that the command is not hard coded. I apologize if the code gets jargoned im new to the board and dont see a tag to place it in to keep it from messing up so im assuming its the tags. Anyways the args in that Execute function are "a memory address" , coins . when i attempt to get coins. being that it made it that far i am assuming it found the correct command since its not equal to the end of the database during that check. I have watched the DB that is generated with commands from python and watched it get all the commands including the "get" command. The exception is the from the Catch block in this function. any command that doesnt deal with items works fine. Anything you need me to hunt down to better help your perspective please let me know.
What I really need to know is exactly what exception you get.
Since you have a catch-all block you can''t tell that from the code.

Right now, I can''t even tell if the error occurs on the C++ or Python side.

For code formatting, use [source][/source] blocks.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Ok, so should i just comment the catch out and let it hang and see what it throws that way or is there another way to go about it that may provide more info.
I''ve left the book at work, so I don''t know if there aren''t more catch blocks in the call stack. Try and see.

If it is a python exception and you can produce a traceback, that would be great.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
heh it seems with each one i comment there is another to catch it somewhere else, im not very adept at debugging obviousely is there a way to store the actual error during the catch and just have it output the errors info to the telnet client instead of the message it is producing to them now.
my folder containing my source and workspace and everything is pretty small. I could easily just send it to you to compile and run. After all its an open source code base so dont see the harm in it. my AIM is OdiousFace
btw you mentioned you left the book, so im assuming you have indeed played with this code base. Did you not experience the same issue in that case? I have 2 friends who are gonna be working with me on this code base once we resolve this issue and they all have had the exact same issue im having which led me to think it was a difference in his source and his last produced exe that he didnt save or something when he published.

This topic is closed to new replies.

Advertisement