Shoutbox

[Request] C/C++ Keywords Script - 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: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Request] C/C++ Keywords Script (/showthread.php?tid=62638)

[Request] C/C++ Keywords Script by Paril on 07-06-2006 at 01:17 AM

Hello everyone.

I'm new to the language (Jscript or whatever) that this uses, although I am skilled in C/C++.

Anyways, I want to try and make a plugin and will turn C/C++ keywords blue, comments green, etc.

I just need a starter, such as a code that will just turn one word blue, and I can do the rest.

I came up with this:

code:
function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{
    if (sMessage.substr(0,1) == "if")
        sMessage.substr(0,1) = "[c=2]if[/c]";
    return sMessage;
}

but that didn't work.

I also tried..


code:
function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{
    if (sMessage == "if")
        sMessage = "[c=2]if[/c]";
    return sMessage;
}

The first one works, but it only works when I say "if" and nothing else.
Any ideas?


-Paril Aughven Kalashnikov
RE: [Request] C/C++ Keywords Script by Silentdragon on 07-06-2006 at 01:26 AM

sMessage.replace(/if/gi,"[c=2]if[/c]);

Should do most of it for you, comments would need to be done a little different.


RE: [Request] C/C++ Keywords Script by Paril on 07-06-2006 at 01:29 AM

Yeah, I thought of that..


RE: [Request] C/C++ Keywords Script by ShawnZ on 07-06-2006 at 01:29 AM

quote:
Originally posted by Paril
The first one works, but it only works when I say "if" and nothing else.

sMessage is the whole message. in the first example, you check if the first letter is "if". in the second, you check if the whole message is "if". use Replace instead.
RE: [Request] C/C++ Keywords Script by Paril on 07-06-2006 at 01:31 AM

Sorry for double post, but

That one you put there, doesn't work.

How do I use it?

just like:

function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{
    if (sMessage == "if")
    sMessage.replace(/if/gi,"[c=2]if[/c]");
    return sMessage;
}


or what?


I want it to change every "if" that is in the text, not just the first one. Even just

function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{
    sMessage.replace(/if/gi,"[c=2]if[/c]");
    return sMessage;
}

doesn't work.
Any ideas?


RE: [Request] C/C++ Keywords Script by Silentdragon on 07-06-2006 at 01:42 AM

sMessage =  sMessage.replace(/if/gi,"[c=2]if[/c]");


RE: [Request] C/C++ Keywords Script by ShawnZ on 07-06-2006 at 01:45 AM

quote:
Originally posted by Paril
just like:

Again, think about it logically. sMessage is the _entire message._ You're checking to see if the entire message is equal to "if", which its not.
RE: [Request] C/C++ Keywords Script by Paril on 07-06-2006 at 01:48 AM

Yeah, I replied before I saw your first message :(

Thanks Silentdragon, I got it.



But now, what about comments?
For one, // would only comment out the current line, but make the next line back to normal (but see, when MSN breaks lines, that messes it up..)

Or, just turning anything inside "/* */" green.. Possible?


-Paril


RE: [Request] C/C++ Keywords Script by ShawnZ on 07-06-2006 at 01:53 AM

you could replace // with Alt0003-3// and replace linefeeds with Alt0003


RE: [Request] C/C++ Keywords Script by Paril on 07-06-2006 at 01:59 AM

Could you post an example please? I am really no good at Jscript :(


[Sorry for Double Post]

Ok, I finished the part with the blue keywords

Problem is, if I do a text that has one of the keywords in it, it turns that blue, example:

[c=12]int[/c] ;

i =ran[c=12]do[/c]m(1-10); // not real..

[c=12]switch[/c](i)
{
          [c=12]case[/c] 1:
    pr[c=12]int[/c]f ("the number is 1");
          [c=12]break[/c];
          [c=12]case[/c] 2:
    printf ("dfh");
          [c=12]break[/c];
          [c=12]default[/c]:
    [c=12]printf[/c] ("it's not 1 or 2!");
          [c=12]break[/c];
}

Any way to stop it from doing like:

ran[c=12]do[/c]m?

Do I, like, change this

    sMessage = sMessage.replace(/do/gi,"[c=12]do[/c]");

to like

    sMessage = sMessage.replace(/do /gi,"[c=12]do[/c]");

and add a space after the first do, so it makes sure it's not part of current text?

-Paril
RE: [Request] C/C++ Keywords Script by Silentdragon on 07-06-2006 at 02:26 AM

sMessage = sMessage.replace(/\bdo\b/gi,"[c=12]do[/c]");


RE: [Request] C/C++ Keywords Script by Paril on 07-06-2006 at 02:35 AM

Thank you :)

Now, what about comments? How do I do that?


[Sorry, yet again for dualpost]

About the last post SilentDragon, how would I do that to this?

    sMessage = sMessage.replace("asm","[c=12]asm[/c]");

do I put asm in a var or something?

EDIT: I was right :)

-Paril
[Triple, sorry :(]

Alright, I got a small block comment thing in.
Problem is, if I do it with a blue keyword, it does this:

[c=3]/*[c=12]true[/c]*/[/c]

Any way to stop this?

-Paril
RE: [Request] C/C++ Keywords Script by matty on 07-06-2006 at 04:57 AM

You should check to see if the keyword is a part of a multiline comment


RE: [Request] C/C++ Keywords Script by Paril on 07-06-2006 at 05:00 AM

I tried that, but it wouldn't let me use comments at all after that.. I must be doing it wrong, I'm not very good at Jscript..