Archived

This topic is now archived and is closed to further replies.

odious

MUD Game Programming By Ron Penton

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
See if this catch block works:


catch (std::exception &e)
{
// Prints any pending python exception with traceback

// Might not do anything useful if SWIG already processed it.

// Output goes to standard error, so you'll probably need to

// have the server running in a console window - I doubt the

// error will be reflected over telnet. We could mess with

// redirection but that's non-trivial, and doesn't provide

// that big of a benefit here.


if(PyErr_Occured()) PyErr_Print();

// Assuming the exception derived from the standard C++ base

// exception class std::exception, and that it has been

// properly constructed, we try and report the exception data.


c.DoAction( "error", 0, 0, 0, 0, e.what() );

return;
}


You may need to include stdexcept to get the definition for std::exception and Python.h for the python stuff. I just hope Ron or the Python folks derived their exceptions from std::exception...


“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


[edited by - Fruny on May 19, 2004 10:42:27 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by odious
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?


No, I didn''t actually play with the code base, but I did argue quite a bit with Ron about its design while he was writing the book. So, yeah, I''m not as helpful as I could be, but at least I know a bit about it.

Right now I''m at a public terminal in a library, so there''s not much I can do with your own files, sorry. Plus I need to go back to my room and continue packing out before the university kicks me out.

I''ll be back this afternoon.


“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

Share this post


Link to post
Share on other sites
which header has that function "PyErr_occured()" and everything in it, It is undefined right now when I compile

Share this post


Link to post
Share on other sites
Heh, well i hope i dont hold you up, this wouldnt be a problem i bet if Ron would update his site for once since the last update took place only a month after his book released. Its very hard to find any after publication help.

Share this post


Link to post
Share on other sites
Typo, should have been PyErr_Occured.


“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

Share this post


Link to post
Share on other sites
well the Doaction sent telnet this
Unknown exception
YAY hehe i was really hoping for something more to be there as to better help this along. Does this mean it was not a python error then?

Share this post


Link to post
Share on other sites
Right now I don''t know. Try pestering Ron in #gamedev on irc.afternet.org (or click ''GDNet Chat Network'' at the top of the page).

I''m off, see you later (maybe in IRC or in ICQ/AIM).


“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

Share this post


Link to post
Share on other sites