Page 1 of 1

Way to inject text from server in chatbox?

Posted: 08 Jul 2011, 01:52
by shaka
Hi all,

I currently have a chatbox (named chatBox_mc). Is there any way I can use the server to display a message inside the chat box?

I tried messageQueue (chatBox_mc.messageQueue += "message" ) but I'm not sure how to do it correctly.

Thanks!

Posted: 08 Jul 2011, 08:38
by Bax
You could send a moderator message.

Posted: 09 Jul 2011, 21:14
by shaka
Hi bax, thanks for your help.

I looked into sending moderator message and found the following page:
http://docs2x.smartfoxserver.com/api-do ... quest.html

which does it for Actionscript. Looking back to my original post, I was pretty uninformative, so let me clarify!

In my game, at the end of each player's turn, the server does several actions which I'd like to have a text footprint (e.g. "Character A was moved to position X, Y!") displayed in the chatbox.

I'm looking at sendModeratorMessage (from here) but have a hard time finding an example of how to use it, as this is my first time programming something significant. Can anyone please give me something to work with?

Thanks again for your help!

Posted: 10 Jul 2011, 12:25
by Bax
What is not clear using the server-side sendModeratorMessage?

Posted: 10 Jul 2011, 20:06
by shaka
I don't know what library I have to import... I've tried
com.smartfoxserver.v2.api.SFSApi (and api.*), but in eclipse, the line: sendModeratorMessage(null, targetname + " takes" + damage + " damage", resObj, recipients);

"sendModeratorMessage" is underlined in red and says that it's not defined.

Posted: 11 Jul 2011, 07:22
by Bax
You must be doing something wrong. Please read again the documentation on Extensions development, and make sure you linked the proper libraries.

Posted: 11 Jul 2011, 17:43
by shaka
Bax, thanks for your help, but I'm still stumped.
I know I've correctly referenced sfs2x.jar and sfs2x-core.jar because I've been sending regular messages to my clients successfully, but my moderator messages still aren't working. :x Is there another library that I need to be referencing? (I can't find it.. :oops: )

Posted: 12 Jul 2011, 08:53
by Bax
Not sure what you are doing wrong. Inside the main extension code, or inside a request handler code, if I write:

Code: Select all

getApi().sendModeratorMessage(arg0, arg1, arg2, arg3)

everything is fine (if entering valid arguments of course).

Posted: 12 Jul 2011, 17:46
by shaka
Hi bax,

With your help, I've solved it! The big problem was i wasn't using getApi() in the beginning.

Thanks a lot for your help!

I actually have another question though: Is there a way to remove the white space between each moderator message? In the chatbox properties, I've set the Moderator message header text as "Game: ", but 2 lines of white space (<br>s?) keep appearing as such:


"

Game: Ranger moves to 4,4


Game: Ranger moves to 3,4

"

How can I remove these white spaces that appear before and after each moderator message?

Posted: 13 Jul 2011, 08:08
by Bax
I'm sorry but you can't (unless you purchased the Bits source code).
Those spaces have been added to highlight the admin/moderator message.

Posted: 13 Jul 2011, 17:44
by shaka
Alright, that's a pity. I've decided to just run with sendPublicMessage and force a user to say a message instead. Thanks for all your help, it saved me a lot of time!