Game Development Community

Mini-Tut: debugging using the chat window

by Sean H. · in Torque Game Engine · 06/11/2006 (11:59 am) · 5 replies

Programmers seem to use echo() command for spitting out data for debugging purposes. the problem with using the echo() command is that it only shows up in the console forcing the programmer to constantly view the console to see the output. a better way of observing values is to use the chatwindow. you can use onServerMessage() to output values to the chat window. this way, values are exposed during gameplay without having to bring up the console window.

say you have a script function and you want to observe the value of a variable %var. you could use:

onServerMessage("value is: "@%var);

and the string will show up in the chathud. =)

#1
06/11/2006 (12:43 pm)
Another way to do it is to use the command:

ChatHud.addLine(%text);

Basically I created a function called outputText() that, among other things, makes this call. So when I want to see something without going to the console, I just call outputText(%text).

But yours is probably the better way to do it since I'm probably not following the server-client structure the proper way.
#2
06/11/2006 (2:17 pm)
The correct way to do it would be to use messageClient() on the server. ChatHud.addLine() is fine if it's in client code. Calling onServerMessage() directly would generally be considered bad practice.

There are examples of messageClient() and it's variants scattered all over the scripts.

T.
#3
06/11/2006 (3:49 pm)
Tom the reason i didnt put that is just because it would require specifying the client which would be a bit more work and I'm a lazy bastard. =)

and remember this would be for debugging only so I wasn't considering whether it would show up on all clients or just the server.
#4
06/11/2006 (4:55 pm)
I started using the message system and found I liked it...:). You can send audio to play from the messaging system, can't you?
#5
06/11/2006 (6:51 pm)
Ah, cool. My calls to ChadHud.addLine() are all client code, so good to know.