Shoutbox

RemoveFormatCodes - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: WLM Plus! Bug Reports (/forumdisplay.php?fid=7)
+----- Thread: RemoveFormatCodes (/showthread.php?tid=85448)

RemoveFormatCodes by Noixe on 08-17-2008 at 11:57 AM

Hello,

I have create a simple function to see the result of RemoveFormatCodes:

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MsgKind) {

    MsgPlus.DisplayToast("Test", ("abcdefghi" == MsgPlus.RemoveFormatCodes(Message)));

                MsgPlus.DisplayToast("Test",  MsgPlus.RemoveFormatCodes(Message));


                           
}

But when I  receive message colored with my script "Random Gradiator" (using Bidirectional Gradation mode), the result of first toast window is "false":

For example, i write:

abcdefghi

it was sent with format code and i see it with color but in the second toast window I see:

abcd    efghi


I have tried to write manually the code generated by Random Gradiator :

MyMsg = "[.b][c=1]abcd[/c=2][c=2]efghi[/c=1][/b.]"

MsgPlus.DisplayToast("Test",  MsgPlus.RemoveFormatCodes(MyMsg));

but in this way the message printed is correct (without spaces).


This is a function used by script to insert color codes:

msg1 = Messaggio.substr(0, Messaggio.length / 2);
msg2 = Messaggio.substr(Messaggio.length / 2);

return BIU_a[form] + "[c=" + c1 + "]" + msg1 + "[/c=" + c2 + "]" +
                            "[c=" + c2 + "]" + msg2 + "[/c=" + c1 + "]" + BIU_c[form];

where c1 and c2 are a numbers

BIU_a is an array with the open tag: [.b], [.i], [.u], etc...

BIU_c is an array with the close tag: [/b.], [/i.], [/u.], etc..

if you want see the source you can download it from:

http://www.msgpluslive.it/scripts/view/429-Random-Gradiator

Thanks

P.S.: I have add the dots in the tag to make it visible.


RE: RemoveFormatCodes by Spunky on 08-17-2008 at 03:54 PM

Why do the tags have periods in them?


RE: RE: RemoveFormatCodes by Noixe on 08-17-2008 at 04:36 PM

quote:
Originally posted by SpunkyLoveMuff
Why do the tags have periods in them?

What's periods?

The dots?
RE: RemoveFormatCodes by Felu on 08-17-2008 at 04:46 PM

quote:
Originally posted by SpunkyLoveMuff
Why do the tags have periods in them?
quote:
Originally posted by Noixe
P.S.: I have add the dots in the tag to make it visible.




quote:
Originally posted by Noixe
quote:
Originally posted by SpunkyLoveMuff
Why do the tags have periods in them?

What's periods?

The dots?
Yes, the dots.

And yea, displaying it as "abcd    efghi" is really weird. What is the exact string that you get when the message is sent? "[b][c=1]abcd[/c=2][c=2]efghi[/c=1][/b]"? Or something different?
RE: RemoveFormatCodes by Noixe on 08-17-2008 at 08:47 PM

I send: abcdefghi
and the result is false.

But if I assign the value in this way:

MyMsg = "[.b][c=1]abcd[/c=2][c=2]efghi[/c=1][/b.]"

MsgPlus.DisplayToast("Test",  MsgPlus.RemoveFormatCodes(MyMsg));

The result is correct, without spaces.

If you want, you can try with Random Gradiator the same thing.

You must choose "Bidirectional gradation".

The function can't remove the format code of string received from message.

Bye


RE: RemoveFormatCodes by CookieRevised on 08-17-2008 at 10:07 PM

Nice catch... (aka: confirmed)

However the bug is not in the RemoveFormatCodes() function. This function acts like it should.

---

The bug is actually how the sMessage parameter is passed to the OnEvent_ChatWndReceiveMessage() event.

If [c=1]abcdef[/c] was received, it will be passed with all the tag characters being replaced by spaces:
(note that the bold tags don't matter, neither does it matter if you use a gradient or not or multiple color tags)


  send: [c=1]abcdef[/c]
passed: _____abcdef____



So your variable sMessage in MsgPlus.RemoveFormatCodes(sMessage) will already be "_____abcdef____" (thus without any tags). And of course its output is exactly the same as there are no tags to replace to begin with.

Example code to reproduce it

code:
function OnEvent_ChatWndReceiveMessage(oChatWnd, sOrigin, sMessage, nMsgKind) {
    Debug.Trace(sMessage);
}

of course, the underscores being used in this post (_) represent spaces ;)
RE: RemoveFormatCodes by Noixe on 08-18-2008 at 09:11 AM

I have tried it and I have see the same output, but I wanted knew also your opinion.

Is not strange this behaviour of sMessage parameter?

However, a solution could be apply a trim function at all substring.

Bye


RE: RemoveFormatCodes by CookieRevised on 08-18-2008 at 05:22 PM

Yep, very strange behaviour.

And also very strange that this bug wasn't noticed before with all those scripts using the OnEvent_ChatWndReceiveMessage().... Especially since the bug exists since the first Plus! Live versions.


RE: RemoveFormatCodes by Noixe on 08-18-2008 at 08:10 PM

Maybe because only Random Gradiator make a massive use of color codes :)

Bye