Shoutbox

[SOLVED] How do I create a variable thing like (!VER)? - 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: [SOLVED] How do I create a variable thing like (!VER)? (/showthread.php?tid=69037)

[SOLVED] How do I create a variable thing like (!VER)? by Agret on 12-01-2006 at 07:43 AM

How do I create a variable thing like (!VER)?

I want it so that when a person writes (!MEH) it's auto-replaced by a variable from my script, how can I accomplish this?


RE: How do I create a variable thing like (!VER)? by markee on 12-01-2006 at 07:48 AM

code:
function OnEvent_ChatWndSendMessage(Wnd,Msg){
...
Msg = Msg.replace(/\(\!MEH\)/g,variable);//replace (!MEH) with string in variable
..
}
If you want it to be case insensitive then use gi rather than just g.  This just uses regular expressions, which I highly recommend for all scripters to learn.
RE: How do I create a variable thing like (!VER)? by Agret on 12-01-2006 at 08:03 AM

Thanks a lot markee, you have been helpful. This forum should get a thanks mod installed :P


RE: How do I create a variable thing like (!VER)? by NiteMare on 12-01-2006 at 08:17 AM

quote:
Originally posted by markee
This just uses regular expressions, which I highly recommend for all scripters to learn.

thats like a whole nother language in itself
RE: How do I create a variable thing like (!VER)? by Agret on 12-01-2006 at 08:28 AM

Heh, i've gotten somewhat used to regular expressions although they vary in usage. UltraEdit and PHP have different regular expressions and now I'll have to learn the JavaScript ones :(

I think it's better to just look up a cheat sheet for regular expressions rather than try and learn them, it'll drive you insane trying to remember which one to use between which language / program.


RE: How do I create a variable thing like (!VER)? by Ezra on 12-01-2006 at 09:09 AM

PHP has two different versions of regex.

IIRC Jscript uses one of these two.

I recommend:
http://www.regular-expressions.info/ along with The Regex Coach


RE: How do I create a variable thing like (!VER)? by Agret on 12-01-2006 at 12:38 PM

markee I finally got around to testing your code and although it replaces the Message thing alright it doesn't actually replace the message that is sent to your recipient, I can only access the new value from a script


RE: How do I create a variable thing like (!VER)? by markee on 12-01-2006 at 12:44 PM

quote:
Originally posted by Agret
markee I finally got around to testing your code and although it replaces the Message thing alright it doesn't actually replace the message that is sent to your recipient, I can only access the new value from a script
Sorry, you have to return the Msg variable, I just put in ... for if you wanted to do more in the script.  If you just want to do that one thing then here is the script.

code:
function OnEvent_ChatWndSendMessage(Wnd,Msg){
Msg = Msg.replace(/\(\!MEH\)/g,variable);//replace (!MEH) with string in variable
return Msg;
}

Btw you can still add more than you want, I just wanted to give you an example or snippet of the code first rather than writing something fully.

RE: How do I create a variable thing like (!VER)? by Felu on 12-01-2006 at 12:46 PM

Markee forgot to return the message [Image: msn_tongue.gif].

code:
var meh = "meh"
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
    Message = Message.replace(/\(\!MEH\)/gi,meh);
return Message;
}

Edit : Beaten by markee :P.
RE: How do I create a variable thing like (!VER)? by Agret on 12-01-2006 at 02:17 PM

Yeah, I figured it out myself. Forgot to delete my post lol :D Thanks for replying anyway guys.

The script is pretty much finished now, just gotta do some usability improvements to it ;)


RE: RE: How do I create a variable thing like (!VER)? by CookieRevised on 12-01-2006 at 07:35 PM

quote:
Originally posted by markee
If you want it to be case insensitive then use gi rather than just g.

I do not recommend using the case insensitive flag. Reason for this is simple: to be consistant with Messenger Plus!.

Tags in Messenger Plus! like (!VER) are case sensitive, so it is better to have that same behaviour in your scripts (just like I would recommend commands to start with "/" and not "!", "^", "$", or whatever else)

There is of course no rule which states you can't use the case insesitive flag, but it should be considered as one of the guidelines in handling commands and tags...

See also CookieRevised's reply to [Release] Change Me!

quote:
Originally posted by Agret
Heh, i've gotten somewhat used to regular expressions although they vary in usage. UltraEdit and PHP have different regular expressions and now I'll have to learn the JavaScript ones :(

I think it's better to just look up a cheat sheet for regular expressions rather than try and learn them, it'll drive you insane trying to remember which one to use between which language / program.
There isn't a fundamental difference between all the variations.

They all work the same. What can be different is that some variations can do more than others (eg: not all variations support back tracking), etc. But the overall way of usage is the same. And that and the logic behind it can be learned.

Once you know how regular expressions work, it is only a very small step to adapt your syntax slightly to accomodate the syntax of the language you're working in.

As for a cheat sheet, that's why there are easy to use help files with a syntax overview of regular expressions :p ;)

In the JScript Documentation, see:
- Contents > JScript > JScript User's Guide > Introduction to Regular Expressions > Regular Expression Syntax
or
- Index > regular expressions > syntax