Author Topic: Chat Channels  (Read 968 times)

I'm making a chat channel script, and I was wondering if how I set it up is a good way.

I created a script object called chatchannelmod.
I set chatchannelmod.chatchannellis t = new simgroup(chatchannels){}; with nothing special.
I then created a function for creating new script objects of the class chatchannel and added them to the simgroup chatchannelmod.chatchannellis t.
Each channel has an array of scriptobjects, called users, which hold values of the users ID and users Name, and a bool like variable to see if the player should send messages to the channel(if they can't send messages to the channel, they can still receive them if they are a member of the channel).

I created functions to remove players from the array, add players, get the count of the array, etc.
If a user is removed from the array, here is an example of what happens: Array Length: 5. Element 3 is needed to be removed. If element 5 is not null, set element 3 equal to element 5. Set element 5 to null.

When ever a message is sent, its sent to each chat channel. If a client is a member of the channel, it sends them the message.

Sorry if I'm not very clear on what I'm doing. If anyone wants to look at the code, I'll post it here.
Some of my problems are:

1. that chatchannelmod.delete(); doesn't delete the script object chatchannelmod, but deletes all the channels in the sim group chatchannellist.
2. is there a way to delete a variable attached to a script object... like my user array off of a channel sooo... channel.channeluser[%i].delete(); so that the variable is wiped completly.
3. I feel like I made this to complicated lol.
« Last Edit: August 15, 2012, 12:51:55 PM by Gartanium »

1. You probably didn't Parent::delete.
2. You don't want to delete a client.
3. Yes, it seems that way.

1. You probably had multiple chat channel objects, you dont need to parent anything.
2. No but you can either set it to ""; or just remake the object.
3. It's not overcomplicated at all.

Also here is how I would do it, keeping it similar to what you had:



Code: [Select]
if(isObject(chatChannelMod))
chatChannelMod.delete();

if(isObject(chatChannelList))
{
chatChannelList.kill();
chatChannelList.delete();
}

new scriptGroup(chatChannelMod)
{

};

new scriptGroup(chatChannelList)
{
Class = CCL;
};

chatChannelMod.add(chatChannelList);

function CCL::newChannel(%this,%chanName)
{
%chanObj = new scriptGroup(%chanName)
{
class = CC;
parent = %this;
channelName = %chanName;
users = 0;
};

return %chanObj;
}

function CCL::deleteChannel(%this,%chanObj)
{
if(isObject(%chanObj))
{
%chanObj.kill();
%this.remove(%chanObj);
%chanObj.delete();
}
}

function CCL::kill(%this)
{
//remove and delete all channels, etc
}

function CC::addUser(%this,%scriptObject)
{
%this.add(%scriptObject);
//set variables for the user's script object if needed
}

function CC::removeUser(%this,%scriptObject)
{
%this.remove(%scriptObject);
//set variables for the user's script object if needed
}

function CC::kill(%this)
{
//remove all players and other stuff before deleting this channel
}



This way, you don't have to make functions to get objects in a channel, get the count, etc. You can just do %chatChannel.getObject(int); & %chatChannel.getCount(); etc.




« Last Edit: August 17, 2012, 10:45:19 AM by elm »

@Xalos
I did do parent::delete (where parent was chatchannelmod)
The mod doesn't store a client, it stores the clients ID.

@ elm
I didn't know there was a thing called a scriptgroup :o.
I think now I know that I'm going to rewrite things.

thanks guys.

Another question I had was what is the best way to intercept a message from a client? I have been using messagesent, but I feel like there is a better way. (maybe chatmessage?).  I want this to be compatible with other scripts but I don't know how to make it compatible (like slayer).

I want the message system to be like this.

Client sends message to server
-> Server reads the message
-> Server sends it to chatchannelmod.sendmessage(%client, %msg)
-> chatchannelmod.sendmessage makes a few checks
1. If %client is in any channel
         a. if %client has chatfocus in that channel
                -> chatchannel.sendmessage(%client, %msg)
                                  for every script object channeluser in the channel scriptgroup
                                        -> send chat message to (findclientbyBL_ID(channeluser.BL_ID))                           
« Last Edit: August 18, 2012, 03:59:01 PM by Gartanium »

@Xalos
I did do parent::delete (where parent was chatchannelmod)
The mod doesn't store a client, it stores the clients ID.      
The client's ID is, for all intents and purposes, the actual client. To get the numeric string identifier use %clID.getID()

The client's ID is, for all intents and purposes, the actual client. To get the numeric string identifier use %clID.getID()

Ok thanks. I will do that now.

Edit: Wait, if its just a refrence of the value(like it only says what the bl_ID is and is not linked to the actual bl_ID) would it matter if I deleted it?

Edit again: nvm I answered my own question.
« Last Edit: August 18, 2012, 04:11:38 PM by Gartanium »

Package servercmdmessagesent(%client,%message) and dont call the parent. If you dont know how to package something, then search.

Package servercmdmessagesent(%client,%message) and dont call the parent. If you dont know how to package something, then search.
I have been doing that, but what happens if two scripts both package something? Slayer has its own package for servercmdmessagesent(%client, %msg) and I don't want to interfere with that. How do I not interfere, or is that something I have to work around.

packages stack, so multiple can exist at the same time if the parent is called properly

packages stack, so multiple can exist at the same time if the parent is called properly

Even with the new update? Something about badspot breaking packages or something with v21.

Even with the new update? Something about badspot breaking packages or something with v21.
should be fixed in r1707

Ok thanks again guys, I'll post if I have another question.


function CCL::newChannel(%this,%chanName)
{
    %chanObj = new scriptGroup(%chanName)
    {
       class = CC;
       parent = %this;
       channelName = %chanName;

    };
   
    return %chanObj;
}

This causes an error which is "cannot change namespace parent linkage from scriptgroup to CC". I understand that the new channelObj is already of the scriptgroup class. So how do I create functions that only chat channels can use but other scriptgroups can't? How can I make a new class that inherits from the scriptgroup class or is this not do able in torque script?

Edit: I guess there is something I don't understand because doing
                                   new scriptgroup(test) { class = "best"; }; returns no errors.
« Last Edit: August 18, 2012, 05:44:49 PM by Gartanium »

after saying %blah = new whatever(name)
you cannotchange its class
if you do new whatever(name) you can.

no, garbage