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?

Pages: (4): « First [ 1 ] 2 3 4 » Last »
[?] Pow... err, triggering some function on certain convo events?
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. [?] Pow... err, triggering some function on certain convo events?
Good, I'm trying to make a calculator script in the conversation window. It has a tab which opens a small typing panel with toolbar underneath the editting panel, so it will look very cool. :P

Now, I'm trying to work out the math functions. I want to let this:
code:
8^2
change into this:
code:
64
by using Math.pow(8, 2). The problem is: how can I replace that? :S
It also has to parse this:

code:
(-9*7)^(7-5)
to:
code:
3969
for example, so brackets should also be parsed first. (I think eval() can help here?)

Okay, Cookie just told me that would be very very hard. (read: too hard for me) So I would like to fix 2 other problems problems:
  • Does anyone know how I can trigger a function when the user shows/hides the display pictures in the conversation window? I'm trying to make the tab be positioned almost perfectly, so this one is quite important for me.
  • Also, is there a way to know if the "is typing message" is shown? I need to call this since if the other contact has emoticons in his/her name, the tab bar gets higher. Therefore, my tab should resize too.
Anyone has an idea to do these? ^o)

This post was edited on 09-16-2006 at 02:31 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
09-16-2006 11:41 AM
Profile E-Mail PM Web Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: [?] Powers
Shouldn't if you take the brackets as well it should work out properly?

* markee goes to check this out

EDIT: confirmed, if you use a regExp taking the brackets then it will work.

This post was edited on 09-16-2006 at 11:55 AM by markee.
[Image: markee.png]
09-16-2006 11:51 AM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. RE: [?] Powers
Then, what expression should I use? Since I'm a bit of n00bish with expressions. :P
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
09-16-2006 12:06 PM
Profile E-Mail PM Web Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: [?] Powers
quote:
Originally posted by Mattike
Then, what expression should I use? Since I'm a bit of n00bish with expressions. [Image: msn_tongue.gif]
I wish I could help, I'm very noobish in that area too.  Maybe PM the likes of Shondoit as he prides himself on his regExp knowledge.  Or you could also maybe hope that the likes of CookieRevised helps you out.
[Image: markee.png]
09-16-2006 12:23 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [?] Powers
It wouldn't be easy.... In fact, it would be hard, especially if you'r not used to regular expressions, parsing (sub)strings and manipulating (sub)strings, and other stuff...

To make what you want you need to make your own eval() function so to speak, from scratch. This means you need to take in account all the possible math operators which are to be used, the operator precedence and what not...

You need to parse each and every operator seperatly (since they can occur in any place in the expression), taking in account parenthesis and brackets and keeping everything in the correct order of precedence, etc etc.

----

To make it a bit easier, you can try to first make a parser which converts the normal math expression (called an infix expression) into a postfix expression (this would be the hardest part).

In that way, you can easly parse/evaluate everything from left to right instead of taking in account parenthesis, order of precedence, etc.

An example of a postfix expression is: "1 2 * 3 +", which will result in 5. Since it is converted from the normal math expression "1*2+3".

There are even already many JavaScript sources for evaluating a postfix expression (as it is actually dead easy). An example, including a very detailed explanation on how it works can be found here:
http://www.qiksearch.com/articles/cs/postfix-evaluation/index.htm

----

Infix notation

What most people understand under a mathematical expression. The operators are written in infix-style.

The major problem with this notation is that it is not that simple to parse. The parentheses surrounding the groups of operands and operators are necessary to indicate the order in which the operations are to be parsed. In the absence of parentheses, certain rules determine the order of operations.

eg1: (5+3)*9
eg2: 9*(5+3)


Postfix notation

Also called Reverse Polish notation (RPN)

This notation is also used in some scientific calculators, mostly in HP calculators. The most noticeable difference is that the operands come before the operator, thus leaving out the need for parentheses.

Unlike infix notation, parsing postfix notations is stack-based: operands are popped from a stack, and results are pushed back into it.

Although this might seem strange at first, postfix has the very big advantage of being extremely easy and fast.

Thus, calculations proceed from left to right.
There are no brackets or parentheses, as they are unnecessary.
Operands precede operator, they are removed as the operation is evaluated.
When an operation is done, the result becomes an operand itself (for later use for other operators).
There are no hidden states, and thus also no need to worry about checking if you have hit an operator or not.

eg1: 5 3 + 9 *
eg2: 9 5 3 + *


Convertion from infix to postfix

This is relativly hard (depends on how much experience you have on the matter). In fact, you better copy existing routines which are trialed and tested before if you don't fully understand the logic behind it.

Here is again a very easy explanation:
http://www.qiksearch.com/articles/cs/infix-postfix/
the source posted there is buggy, see the updated source here:
http://www.qiksearch.com/javascripts/infix-postfix.htm
http://www.codingforums.com/showthread.php?t=5692


Others:
http://www.cs.man.ac.uk/~pjj/cs2121/fix.html
http://www.unf.edu/~rzucker/cot3100dir/parser.html
http://trubetskoy1.narod.ru/english/alg/ppne.html

This post was edited on 09-17-2006 at 10:48 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-16-2006 01:27 PM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. RE: [?] Powers
Oh damn... :|
But what about decimal numbers like 1.5? Those can't be processed through a postfix expressions, or am I wrong?

This post was edited on 09-16-2006 at 02:05 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
09-16-2006 02:02 PM
Profile E-Mail PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [?] Powers
quote:
Originally posted by Mattike
Oh damn... :|
But what about decimal numbers like 1.5? Those can't be processed through a postfix expressions, or am I wrong?
1.5 is just a number like everything else... so yes, it can be parsed.

In fact, you can parse whatever you want including functions you invent yourself.

eg:
Infix: (1.5 + 98) * 2 ^ blah(4)
Postfix: 1.5 98 + 2 4 blah ^ *

PS: I updated my previous post with some links which explain everything in detailed way. It is a very good base to start of with.







PSS: why don't you work further on your CountDown Live script? some stuff todo there ;)

This post was edited on 09-16-2006 at 02:31 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-16-2006 02:11 PM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. RE: [?] Pow... err, triggering some function on certain convo events?
Right... ^o) I think I'll wait a bit with such functions and keep it simple so far. :P Whenever I got really nothing, but nothing to do, I can think about it. :)
I'm having lots more problems with the tab itself to change position when the user shows/hides the display pictures, or when the "is typing" message contains emoticons. Read the first post for more, detailed information. ;)

This post was edited on 09-16-2006 at 02:32 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
09-16-2006 02:25 PM
Profile E-Mail PM Web Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
RE: [?] Pow... err, triggering some function on certain convo events?
If I were you, instead of a tab, you could make it a command that popped the answer in a toast.

Instead of checking when the dps are closed, you can just reposition it on a timer. (100 ms will work well :P)
09-16-2006 08:00 PM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. RE: [?] Pow... err, triggering some function on certain convo events?
quote:
Originally posted by deAd
If I were you, instead of a tab, you could make it a command that popped the answer in a toast.
That kills the idea. The thing was to share your calculations with your contacts, not calculating some things for yourself. And I wanted to try something different of simple commands, but I'll make it possible. (that won't be too hard after all)

quote:
Instead of checking when the dps are closed, you can just reposition it on a timer. (100 ms will work well :P)
I already have a timer which repositions the tab/box, since it has to follow when the user resizes the window. The problem is that the script has to know if the DPs are shown or not, so it can change the distance of the right side of the window. ;)

This post was edited on 09-17-2006 at 01:01 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
09-17-2006 09:19 AM
Profile E-Mail PM Web Find Quote Report
Pages: (4): « First [ 1 ] 2 3 4 » Last »
« Next Oldest Return to Top Next Newest »


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