MMO-like chat box
by DMT · in Torque 3D Beginner · 05/12/2010 (11:40 am) · 8 replies
Hey!
I am trying to make an MMO style chat box inside a game. I have a couple of questions but first and foremost , is this feature present already? Maybe in chatHud/MainChatHud? If so, how do I utilize them.
In any case, how would one handle communication between clients? Would this be a commandToServer? I am thinking you would send a command to the server which would update the chat window of all clients either in an area or the whole server. Is there a more effective way to do this?
So my questions are two fold :
1. GUI - Is it already there? If so, how do I use it. If not, what do you recommend?
2. What is the best way to allow clients to communicate to many other clients?
Thanks.
I am trying to make an MMO style chat box inside a game. I have a couple of questions but first and foremost , is this feature present already? Maybe in chatHud/MainChatHud? If so, how do I utilize them.
In any case, how would one handle communication between clients? Would this be a commandToServer? I am thinking you would send a command to the server which would update the chat window of all clients either in an area or the whole server. Is there a more effective way to do this?
So my questions are two fold :
1. GUI - Is it already there? If so, how do I use it. If not, what do you recommend?
2. What is the best way to allow clients to communicate to many other clients?
Thanks.
About the author
#2
Did you use this resource in TGE or T3D? If you used T3D, how was the porting process? I can't yet tell by looking what will port easily or if it will have deprecated functions/names/other?.
Anyway, thanks. I will definitely look into this. As for IRC, don't you need a separate server for that? But I suppose you would have the benefit of having a copy of the message logs.
05/12/2010 (1:25 pm)
I try to stay away from a lot of the old stuff, as it can be difficult to port it for me, being a beginner and all. But this looks pretty good, I look more into it soon. Did you use this resource in TGE or T3D? If you used T3D, how was the porting process? I can't yet tell by looking what will port easily or if it will have deprecated functions/names/other?.
Anyway, thanks. I will definitely look into this. As for IRC, don't you need a separate server for that? But I suppose you would have the benefit of having a copy of the message logs.
#3
If you're doing a network-based game, it's best to separate the boxes like that anyway, but you could get away with running multiple servers on a single box (just means that when it goes down, the entire game goes down instead of just some of the game going down).
05/12/2010 (1:43 pm)
I used it in T3D. Pretty much works as advertised, since it's script.Quote:As for IRC, don't you need a separate server for that?
If you're doing a network-based game, it's best to separate the boxes like that anyway, but you could get away with running multiple servers on a single box (just means that when it goes down, the entire game goes down instead of just some of the game going down).
#4
Also, that resource is full of errors. Anyway, in the lines that go like :
while( (!chatPageDown.isVisible()) && ($ChatRoom.getNumLines()) && ($ChatRoom.getNumLines() >= $pref::HudMessageLogSize))
I get an error like this :
scripts/client/chatHud.cs (294): Unable to find object: 'ChatRoom' attempting to call function 'getNumLines'
scripts/client/chatHud.cs (304): Unable to find object: 'ChatRoom' attempting to call function 'pushBackLine'
So I wrote a this before it :
error($ChatRoom.getNumLines());
and I get the same error. Unable to find object.
Funny thing is that in the console if I copy and paste the above line, I get a proper out put. That is just bizarre. A line referencing a global variable works in the console but not in script.
Any ideas? Also, thanks Ted for the help so far.
05/19/2010 (1:01 pm)
I ran into an error and I have no idea what is going wrong. Also, that resource is full of errors. Anyway, in the lines that go like :
while( (!chatPageDown.isVisible()) && ($ChatRoom.getNumLines()) && ($ChatRoom.getNumLines() >= $pref::HudMessageLogSize))
I get an error like this :
scripts/client/chatHud.cs (294): Unable to find object: 'ChatRoom' attempting to call function 'getNumLines'
scripts/client/chatHud.cs (304): Unable to find object: 'ChatRoom' attempting to call function 'pushBackLine'
So I wrote a this before it :
error($ChatRoom.getNumLines());
and I get the same error. Unable to find object.
Funny thing is that in the console if I copy and paste the above line, I get a proper out put. That is just bizarre. A line referencing a global variable works in the console but not in script.
Any ideas? Also, thanks Ted for the help so far.
#5
05/19/2010 (9:44 pm)
Looks like $ChatRoom might not be getting assigned the object- have you checked to make sure that it gets assigned at least a default object to use for chat? If not, that would explain at least part of what you're seeing.
#6
And I can check it's value through that. And it all checks out, the problem arises when I, in the same instance of the game, do it in script. Here is the function in which I am trying to use it, it is from the resource :
So basically, anywhere there is a $chatroom that the code can reach, t will give me stuff like :
scripts/client/chatHud.cs (271): Unable to find object: 'ChatRoom' attempting to call function 'getNumLines'
scripts/client/chatHud.cs (304): Unable to find object: 'ChatRoom' attempting to call function 'pushBackLine'
But calling it through the console works. And if it were not initialized it would not work, right?
05/20/2010 (10:46 am)
Well the thing is, I can call all the functions in the console. And I can check it's value through that. And it all checks out, the problem arises when I, in the same instance of the game, do it in script. Here is the function in which I am trying to use it, it is from the resource :
function tester(){
$numLines = $ChatRoom.getNumLines();
}
function ChatHud::addLine(%this,%text)
{
//first, see if we're "scrolled up"...
%textHeight = %this.profile.fontSize + %this.lineSpacing;
if (%textHeight <= 0)
%textHeight = 12;
%scrollBox = %this.getGroup();
%chatScrollHeight = getWord(%scrollBox.extent, 1) - 2 * %scrollBox.profile.borderThickness;
%chatPosition = getWord(%this.extent, 1) - %chatScrollHeight + getWord(%this.position, 1) - %scrollBox.profile.borderThickness;
%linesToScroll = mFloor((%chatPosition / %textHeight) + 0.5);
if (%linesToScroll > 0)
%origPosition = %this.position;
////////////////////////////ERROR////////////////
//remove old messages from the top only if scrolled down all the way
while( (!chatPageDown.isVisible()) && ($ChatRoom.getNumLines()) && ($ChatRoom.getNumLines() >= $pref::HudMessageLogSize))
{
%tag = $ChatRoom.getLineTag(0);
if(%tag != 0)
%tag.delete();
$ChatRoom.popFrontLine();
}
////////////////////////////ERROR////////////////
//add the message...
$ChatRoom.pushBackLine(%text, $LastHudTarget);
$LastHudTarget = 0;
//now that we've added the message, see if we need to reset the position
if (%linesToScroll > 0)
{
chatPageDown.setVisible(true);
%this.position = %origPosition;
}
else
chatPageDown.setVisible(false);
}So basically, anywhere there is a $chatroom that the code can reach, t will give me stuff like :
scripts/client/chatHud.cs (271): Unable to find object: 'ChatRoom' attempting to call function 'getNumLines'
scripts/client/chatHud.cs (304): Unable to find object: 'ChatRoom' attempting to call function 'pushBackLine'
But calling it through the console works. And if it were not initialized it would not work, right?
#7
Make sure you initialize $ChatRoom on the client side before the call to getNumLines and pushBackLine. The console executes commands on the server side. Probably not an issue here, but having $ChatRoom initialized on the server side with a LocalClientConnection could lead to something like this. I think it's just a problem with the order of executing the assignment after the tester function.
05/20/2010 (2:15 pm)
I think that the initialization happening later than the actual call to getNumLines. When getNumLines is called, $ChatRoom is not yet assigned a value, or it is, but on the server side.Make sure you initialize $ChatRoom on the client side before the call to getNumLines and pushBackLine. The console executes commands on the server side. Probably not an issue here, but having $ChatRoom initialized on the server side with a LocalClientConnection could lead to something like this. I think it's just a problem with the order of executing the assignment after the tester function.
#8
I also solved my most important problems by attaching the message vectors to the GUI controls. An obvious thing, but I was not aware of it.
05/24/2010 (1:04 pm)
Thanks Ted and Konrad, after spending some time looking around, I found that I was initializing it to the wrong thing! I also solved my most important problems by attaching the message vectors to the GUI controls. An obvious thing, but I was not aware of it.
Torque 3D Owner Ted Southard
There are also IRC implementations that have been used that you may want to look into. Hope that helps.