Game Development Community

TNL Hello World update

by (Sean) Jeffrey Cooper · in Torque Game Engine · 01/23/2006 (9:17 pm) · 3 replies

I suggest you update your hello world sample found here:
http://opentnl.sourceforge.net/doxydocs/simpletutorial.html

Its using const char*'s where it should be using StringPtr's and also its missing the argsNames for the RPC implmentations

// declare the client to server message
TNL_DECLARE_RPC(rpcMessageClientToServer, (const char *theMessageString));

// declare the server to client message
TNL_DECLARE_RPC(rpcMessageServerToClient, (const char *theMessageString));

should be:

// declare the client to server message
TNL_DECLARE_RPC(rpcMessageClientToServer, (StringPtr theMessageString));

// declare the server to client message
TNL_DECLARE_RPC(rpcMessageServerToClient, (StringPtr theMessageString));

and lets not forget:

[cope]
TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageClientToServer, (const char *messageString),
NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0)
{
// display the message the client sent
printf("Got message from client: %s\n", messageString);
// send a hello world back to the client.
rpcMessageServerToClient("Hello, World!");
}

TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageServerToClient, (const char *messageString),
NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirServerToClient, 0)
{
// display the message the server sent
printf("Got a message from server: %s\n", messageString);

// once the client has heard back from the server, it should quit.
gQuit = true;
}
[/code]

which needs to be changed to:

TNL_IMPLEMENT_RPC(
				  SimpleEventConnection, 
				  rpcMessageClientToServer, 
				  (StringPtr messageString), 
				  (messageString),
				NetClassGroupGameMask, 
				RPCGuaranteedOrdered, 
				RPCDirClientToServer, 
				0)
{
    // display the message the client sent
    printf("Got message from client: %s\n", messageString);
    // send a hello world back to the client.
    rpcMessageServerToClient("Hello, World!");
}

TNL_IMPLEMENT_RPC(
				  SimpleEventConnection, 
				  rpcMessageServerToClient, 
				  (StringPtr messageString), 
				  (messageString),
				NetClassGroupGameMask, 
				RPCGuaranteedOrdered, 
				RPCDirServerToClient, 
				0)
{
    // display the message the server sent
    printf("Got a message from server: %s\n", messageString);

    // once the client has heard back from the server, it should quit.
    gQuit = true;
}

I believe that was all the problems.
Thanks

-Sean

About the author

Recent Threads


#1
01/23/2006 (9:57 pm)
With those changes I've been trying to get the expected output but I don't. Rather weird.

Its getting the messages just fine, but this is the out from the server:
"Got message from client: ☻ 7"

IDK what that symbol is and that 7 was a little debug info i put in where it would "strlen(messageString)". So the string works fine when passed to strlen, but not printf

client:
"Got a message from server: ☻ 13"
Again, IDK what that symbol is, and that 13 is part of debug code i put in

BUT, if I do this:
TNL_IMPLEMENT_RPC(
				  SimpleEventConnection, 
				  rpcMessageClientToServer, 
				  (StringPtr messageString), 
				  (messageString),
				NetClassGroupGameMask, 
				RPCGuaranteedOrdered, 
				RPCDirClientToServer, 
				0)
{
	char buffer[256];
	memset(buffer, 0, sizeof(buffer));
	strcpy(buffer, messageString);
    // display the message the client sent
    printf("Got message from client: %s %d\n", buffer, strlen(messageString));
    // send a hello world back to the client.
    rpcMessageServerToClient("Hello, World!");
}

It works fine. How is printf messing up the string parameter :?
I would hate to have to create a temp buffer in earch place where I needed to output something :\.
#2
01/23/2006 (10:18 pm)
I feel stupid
http://www.garagegames.com/mg/forums/result.thread.php?qt=31993

:X
At least I found my printf problem solution :D
#3
01/03/2007 (11:22 pm)
Lifesavers, thanks guys