What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [?] Pow... err, triggering some function on certain convo events?

[?] Pow... err, triggering some function on certain convo events?
Author: Message:
phalanxii
Full Member
***


Posts: 146
Reputation: 5
32 / Male / Flag
Joined: Aug 2006
Status: Away
RE: [?] Pow... err, triggering some function on certain convo events?
Awesome! This is just what I need. :) For those of you who want it, here's a little code that I made for this:
code:
var Angle = "Radian";

function OnEvent_ChatWndEditKeyDown(ChatWnd, KeyCode, CtrlKeyDown, ShiftKeyDown){
   if(KeyCode == 116 && !CtrlKeyDown && !ShiftKeyDown) {
      var x = ChatWnd.EditText.substring(ChatWnd.EditText_GetCurSelStart(), ChatWnd.EditText_GetCurSelEnd()).Calculate()
      if(x != undefined) {
         ChatWnd.EditText_ReplaceSel(x)
      }
   }
}
This is to add to Shondoit's calculator so that you can use it in your chats. All you have to do, is type your expression, highlight it and press F5. Also, you can change Angle to "Radian", "Degree", or "Grad" (as seen in Shondoit's script). :D

Also, Shondoit you might want to check:
code:
if (/^Math\.(a(?:sin|cos|tan2?))\((.+)\)$/.test(Token)) {
   var Func = "Math." + RegExp.$1 + "(" + RegExp.$2 + ")/Math.PI"
   if (/^degrees?$/i.test(Angle)){
      Token = Func + "*180"
   } else if (/^grads?$/i.test(Angle)) {
      Token = Func + "*200"
   }
   [b]Token = Token.Calculate()[/b]
}
When I debug trace it, it seems that this loops because the angle setting is not changed. Perhaps change this to Token = eval(Token)?

-----

EDIT: Thought I might just add this in. If you want to make your own custom calculator functions, add the following code inside the script (you will need to match where it goes):
code:
      Token = eval(Token)
   }
else if (typeof(Custom[Token.toLowerCase()])=="function" || eval("typeof("+Token+")=='function'")) {
   if (eval("typeof("+Token+")!='function'")) {
      Token = "Custom." + Token.toLowerCase()
   }
   Token += this.charAt(i++ + 1)
   var ParamToken = ""
   var Parentheses = 0
   while ((/[^)]/.test(this.charAt(i + 1)) || Parentheses > 0) && i < this.length) {
      if (this.charAt(i + 1) == "(") Parentheses++; else if (this.charAt(i + 1) == ")") Parentheses--
      ParamToken += this.charAt(i++ + 1)
   }
   var Params = ParamToken.split(/\s*,\s*/)
   for (Index in Params) {
      Params[Index] = Params[Index].Calculate()
   }
   Token += Params.join(",")
   Token += this.charAt(i++ + 1)
}
else {
   PopStack("*")
}
If you know how to shorten this into the code, that would be great (Y).

Next, you define your own functions like this (these are a few of mine):
code:
var Custom = {
   "base" : function (Number, FromBase, ToBase) {
      if (Number != Math.floor(Number) || FromBase != Math.floor(FromBase) || ToBase != Math.floor(ToBase)) return undefined
      Number = String(Number)
      if (FromBase < 2) FromBase = 2
      if (FromBase > 10) FromBase = 10
      if (ToBase < 2) ToBase = 2
      if (ToBase > 36) ToBase = 36
      var Internal = 0
      var Character
      for (var i = Number.length - 1; i >= 0; i--) {
         Character = Number.charAt(i)
         if (Character >= FromBase) return undefined
         Internal += Character * Math.pow(FromBase, Number.length - 1 - i)
      }
      var Result = ""
      while (Internal > 0) {
         if (Internal % ToBase > 9) Result = String.fromCharCode(Internal % ToBase + 55) + Result
         else Result = Internal % ToBase + Result
         Internal = Math.floor(Internal / ToBase)
      }
      return Result
   },
   "choose" : function (Total, Choose) {
      if (Total == Choose || Total == 0 || Choose == 0) return 1
      if (Choose > Total) return 0
      Result = eval(Factorial(Total) + "/(" + Factorial(Total - Choose) + "*" + Factorial(Choose) + ")")
      return Result
      function Factorial (Number) {
         var Factorial = ""
         for (var i = 1; i < Number; i++) {
            Factorial += i + "*"
         }
         Factorial += Number
         return Factorial
      }
   },
   "root" : function (Base, Root) {
      if (Root == undefined) Root = 2
      return Math.pow(Base, 1 / Root)
   }
}
These functions work normally, like "choose(5,4)" will return 5. (Just if you wanted to know, "base" converts bases, "choose" finds the number of ways to choose k objects from n (max: 170, otherwise it returns infinity), and "root" finds the nth root of a number.)

-----

EDIT #2: I also noticed that you can't type negative numbers in your expression...?

This post was edited on 09-19-2006 at 02:57 AM by phalanxii.
09-18-2006 11:15 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[?] Pow... err, triggering some function on certain convo events? - by Matti on 09-16-2006 at 11:41 AM
RE: [?] Powers - by markee on 09-16-2006 at 11:51 AM
RE: [?] Powers - by Matti on 09-16-2006 at 12:06 PM
RE: [?] Powers - by markee on 09-16-2006 at 12:23 PM
RE: [?] Powers - by CookieRevised on 09-16-2006 at 01:27 PM
RE: [?] Powers - by Matti on 09-16-2006 at 02:02 PM
RE: [?] Powers - by CookieRevised on 09-16-2006 at 02:11 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-16-2006 at 02:25 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by deAd on 09-16-2006 at 08:00 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-17-2006 at 09:19 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-17-2006 at 10:18 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Plik on 09-17-2006 at 12:30 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-17-2006 at 12:38 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by markee on 09-17-2006 at 12:46 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-17-2006 at 01:04 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-17-2006 at 03:30 PM
RE: RE: [?] Pow... err, triggering some function on certain convo events? - by CookieRevised on 09-17-2006 at 11:03 PM
RE: RE: RE: [?] Pow... err, triggering some function on certain convo events? - by deAd on 09-17-2006 at 11:18 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by CookieRevised on 09-17-2006 at 11:42 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-18-2006 at 03:54 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-18-2006 at 05:57 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-18-2006 at 08:02 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-18-2006 at 11:09 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-18-2006 at 06:35 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-18-2006 at 08:07 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-18-2006 at 11:15 PM
RE: RE: [?] Pow... err, triggering some function on certain convo events? - by CookieRevised on 09-19-2006 at 06:34 AM
RE: RE: RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-19-2006 at 06:48 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-19-2006 at 05:20 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by CookieRevised on 09-19-2006 at 10:50 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-19-2006 at 12:16 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-19-2006 at 06:33 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-19-2006 at 08:53 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-20-2006 at 12:31 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-20-2006 at 05:06 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On