Question Reguarding Chat (Chapter 23)
by Richard Preziosi · in Torque Game Engine · 04/19/2008 (11:45 am) · 2 replies
Hi, was going throught the book and was interested in putting a chat type function into my game. My game setup is nothing like the one in the book, but I figured I would try and accomplish using his chat system as it was the only resource I could find on a chat that performed the way I wanted. Anyways, I've gotten the chat and message box to show up, it successfully displays, the welcome message, but any typed message after that does not show up, the box will page down when i send the message, here is a picture of what I get in the console:

I'm going to post the code I am using, but as a side note I am using the tutorial.base style setup, really no new files than what comes in that, adding them as needed.
My main.cs initClient function where chatbox and message box are called
My ./client/Chatbox.cs

I'm going to post the code I am using, but as a side note I am using the tutorial.base style setup, really no new files than what comes in that, adding them as needed.
My main.cs initClient function where chatbox and message box are called
function initClient()
{
echo("\n--------- Initializing TTB: Client ---------");
// The common module provides basic client functionality
initBaseClient();
// InitCanvas starts up the graphics system.
// The canvas needs to be constructed before the gui scripts are
// run because many of the controls assume the canvas exists at
// load time.
initCanvas("Torque Tutorial Base");
// Load client-side Audio Profiles/Descriptions
exec("./client/audioProfiles.cs");
// Load up the shell and game GUIs
exec("./client/ui/PlayGui.gui");
exec("./client/ui/mainMenuGui.gui");
exec("./client/ui/optionsDlg.gui");
exec("./client/ui/loadingGui.gui");
exec("./client/ui/chatbox.gui");
exec("./client/ui/messagebox.gui");
// Client scripts
exec("./client/optionsDlg.cs");
exec("./client/missionDownload.cs");
exec("./client/serverConnection.cs");
exec("./client/loadingGui.cs");
exec("./client/playGui.cs");
exec("./client/clientGame.cs");
exec("./client/chatbox.cs");
exec("./client/messagebox.cs");
// Default player key bindings
exec("./client/default.bind.cs");
// Copy saved script prefs into C++ code.
setShadowDetailLevel( $pref::shadows );
setDefaultFov( $pref::Player::defaultFov );
setZoomSpeed( $pref::Player::zoomSpeed );
// Start up the main menu...
Canvas.setContent(MainMenuGui);
Canvas.setCursor("DefaultCursor");
}My ./client/Chatbox.cs
new MessageVector(MsgBoxMessageVector);///***KCF CHAT
$LastframeTarget = 0;///***KCF CHAT
function onChatMessage(%message, %voice, %pitch)
{
echo("*****************************************");
echo("GetWordCount(%message):",GetWordCount(%message));
echo("%message:",%message);
if (GetWordCount(%message)) {
ChatBox.AddLine(%message);
}
}
function onServerMessage(%message)
{
if (GetWordCount(%message)) {
ChatBox.AddLine(%message);
}
}
new MessageVector(MsgBoxMessageVector);
$LastframeTarget = 0;
function ChatBox::addLine(%this,%text)
{
%textHeight = %this.profile.fontSize;
if (%textHeight <= 0)
%textHeight = 12;
%chatScrollHeight = getWord(%this.getGroup().getGroup().extent, 1);
%chatPosition = getWord(%this.extent, 1) - %chatScrollHeight +
getWord(%this.position, 1);
%linesToScroll = mFloor((%chatPosition / %textHeight) + 0.5);
if (%linesToScroll > 0)
%origPosition = %this.position;
while( !chatPageDown.isVisible() && MsgBoxMessageVector.getNumLines() &&
(MsgBoxMessageVector.getNumLines() >= $pref::frameMessageLogSize))
{
%tag = MsgBoxMessageVector.getLineTag(0);
if(%tag != 0)
%tag.delete();
MsgBoxMessageVector.popFrontLine();
}
MsgBoxMessageVector.pushBackLine(%text, $LastframeTarget);
$LastframeTarget = 0;
if (%linesToScroll > 0)
{
chatPageDown.setVisible(true);
%this.position = %origPosition;
}
else
chatPageDown.setVisible(false);
}
Torque Owner Richard Preziosi
WinterLeaf Entertainment
function MessageBox::Open(%this) { %offset = 6; if(%this.isVisible()) return; %windowPos = "8 " @ ( getWord( outerChatFrame.position, 1 ) + getWord( outerChatFrame.extent, 1 ) + 1 ); %windowExt = getWord( OuterChatFrame.extent, 0 ) @ " " @ getWord( MessageBox_Frame.extent, 1 ); %textExtent = getWord(MessageBox_Text.extent, 0); %ctrlExtent = getWord(MessageBox_Frame.extent, 0); Canvas.pushDialog(%this); MessageBox_Frame.position = %windowPos; MessageBox_Frame.extent = %windowExt; MessageBox_Edit.position = setWord(MessageBox_Edit.position, 0, %textExtent + %offset); MessageBox_Edit.extent = setWord(MessageBox_Edit.extent, 0, %ctrlExtent - %textExtent - (2 * %offset)); %this.setVisible(true); deactivateKeyboard(); MessageBox_Edit.makeFirstResponder(true); } function MessageBox::Close(%this) { if(!%this.isVisible()) return; Canvas.popDialog(%this); %this.setVisible(false); if ( $enableDirectInput ) activateKeyboard(); MessageBox_Edit.setValue(""); } function MessageBox::ToggleState(%this) { if(%this.isVisible()) %this.close(); else %this.open(); } function MessageBox_Edit::OnEscape(%this) { MessageBox.close(); } function MessageBox_Edit::Eval(%this) { %text = trim(%this.getValue()); if(%text !$= "") commandToServer('MessageSent', %text); MessageBox.close(); } function ToggleMessageBox(%make) { if(%make) MessageBox.toggleState(); }My ./client/playgui.cs
//----------------------------------------------------------------------------- // PlayGui is the main TSControl through which the game is viewed. //----------------------------------------------------------------------------- function PlayGui::onWake(%this) { // Turn off any shell sounds... // alxStop( ... ); $enableDirectInput = "1"; activateDirectInput(); // Show Chat Canvas.pushDialog(MainChatBox);///***KCF CHAT chatBox.attach(MsgBoxMessageVector);///***KCF CHAT // Activate the game's action map moveMap.push(); }My ./client/default.bind.cs
//------------------------------------- // Chat binds function pageMessageBoxUp( %val ) { if ( %val ) PageUpMessageBox(); } function pageMessageBoxDown( %val ) { if ( %val ) PageDownMessageBox (); } moveMap.bind(keyboard, "enter", ToggleMessageBox ); moveMap.bind(keyboard, "PageUp", PageMessageBoxUp ); moveMap.bind(keyboard, "PageDown", PageMessageBoxDown ); [*/code] And finally my ./server/game.cs [*code] //---------------------------------------------------------------------------- // Server chat message handlers function serverCmdTeamMessageSent(%client, %text) { if(strlen(%text) >= $Pref::Server::MaxChatLen) %text = getSubStr(%text, 0, $Pref::Server::MaxChatLen); chatMessageTeam(%client, %client.team, '\c3%1: %2', %client.name, %text); } function serverCmdMessageSent(%client, %text) { if(strlen(%text) >= $Pref::Server::MaxChatLen) %text = getSubStr(%text, 0, $Pref::Server::MaxChatLen); chatMessageAll(%client, '\c4%1: %2', %client.name, %text); }Any help is greatly appreciated, I'd actually like to make this into a resource after I have all the bugs worked out, couldn't find anything on adding just a chat system, and I will definitely be giving credit to whoever can help me get this working. Thanks in advance.