What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [split] What scripts can't do.

[split] What scripts can't do.
Author: Message:
waterbottle
New Member
*


Posts: 6
Joined: Dec 2006
O.P. RE: What scripts can't do.
A bit offtopic but,
is it possible to do bitwise comparision in JScript? (like &, | etc in C).

for example something like; if(Message.charAt(0) & 1) { /*do something if the bit 1 in the frst letter of Message is true*/ }

I tried & but that didn't work...
12-13-2006 09:18 PM
Profile E-Mail PM Find Quote Report
Felu
Veteran Member
*****


Posts: 2223
Reputation: 72
30 / Male / Flag
Joined: Apr 2006
Status: Away
RE: What scripts can't do.
quote:
Originally posted by waterbottle
A bit offtopic but,
is it possible to do bitwise comparision in JScript? (like &, | etc in C).

for example something like; if(Message.charAt(0) & 1) { /*do something if the bit 1 in the frst letter of Message is true*/ }

I tried & but that didn't work...
You have to use && or ||. You might like to check this out too. http://www.msgpluslive.net/scripts/view/152-Windo...ipt-Documentation/
12-14-2006 10:30 AM
Profile E-Mail PM Web Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: What scripts can't do.
&& and || are not bitwise operators but boolean operators...

There are bitwise operators (see the MSDN for more info) but you can't use them on characters because the characters are just strings of length 1 (if I am not mistaking) and not numbers...
12-14-2006 10:58 AM
Profile E-Mail PM Find Quote Report
Mnjul
forum super mod
******

Avatar
plz wub me

Posts: 5396
Reputation: 58
– / Other / Flag
Joined: Nov 2002
Status: Away
RE: [split] What scripts can't do.
You need to use charCodeAt method, waterbottle :)
12-14-2006 03:07 PM
Profile PM Web Find Quote Report
waterbottle
New Member
*


Posts: 6
Joined: Dec 2006
O.P. RE: [split] What scripts can't do.
hmm,
I've been trying to get the charCodeAt function working. However it just dosn't want to.

I copied out of the example, but it gives me the same result everytime I choose a letter (upper or lowercase makes no difference) or anything else other than numbers. I also tried adding other signs to the string, str, (lowercase alphabet, numbers). But that only increases the size of the number it returns.

the number I get with the code copied out of the example is 65. if the char I send is a number it returns '65 + n'.

heres the code I have,

code:
function charCodeAtTest( n ){

  var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //Initialize variable.

   return str.charCodeAt(n - 1);  //Return Unicode value of the character.

}


function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
    return '' + charCodeAtTest(Message.charAt(0));
}


Anyone know what I'm doing wrong? :)
12-15-2006 10:30 PM
Profile E-Mail PM Find Quote Report
Plik
Veteran Member
*****

Avatar

Posts: 1489
Reputation: 46
35 / Male / –
Joined: Jun 2004
RE: [split] What scripts can't do.
quote:
Originally posted by waterbottle
code:
function charCodeAtTest( n ){

  var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //Initialize variable.

   return str.charCodeAt(n - 1);  //Return Unicode value of the character.

}


function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
    return '' + charCodeAtTest(Message.charAt(0));
}


Anyone know what I'm doing wrong? :)
In that code you are passing a char (or a 1 byte string) to the function, you are then treating it as an integer when you subtract one. And if im not mistaken the n - 1 part would equate to NaN (not a number) because you are subtracting one from a string. I don't really understand what you are trying todo so i can't really give you any tips :P
12-15-2006 11:06 PM
Profile PM Find Quote Report
waterbottle
New Member
*


Posts: 6
Joined: Dec 2006
O.P. RE: [split] What scripts can't do.
the example said - 1 so I added that too... I also tried without it, still didn't work.

What I'm trying to do first is get the ascii equivalent of the char.
for example, ' ' = 32, 'a' = 97, 'b' = 98, 'A' = 65, '1' = 49.

This post was edited on 12-15-2006 at 11:18 PM by waterbottle.
12-15-2006 11:18 PM
Profile E-Mail PM Find Quote Report
Plik
Veteran Member
*****

Avatar

Posts: 1489
Reputation: 46
35 / Male / –
Joined: Jun 2004
RE: [split] What scripts can't do.
quote:
Originally posted by waterbottle
What I'm trying to do first is get the ascii equivalent of the char.
for example, ' ' = 32, 'a' = 97, 'b' = 98, 'A' = 65, '1' = 49.
in that case all you need todo is use charCodeAt, like so

code:
function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
return '' + Message.charCodeAt(0);
}

And that will return the ascii code of the first char of the message
12-15-2006 11:37 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [split] What scripts can't do.
quote:
Originally posted by waterbottle
the example said - 1 so I added that too... I also tried without it, still didn't work.
Because, as Plik said, you pass a character as parameter to the function charCodeAtTest( n ) in this code:
code:
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
    return '' + charCodeAtTest(Message.charAt(0));
}
because charAt(0) will return the first character in the string Message.

So the parameter n in your function charCodeAtTest( n ) is a character, not a number...

And a character minus a number (thus your n-1) results in error code NaN...

And charCodeAt() expects a number (character position, starting from 0 for the first character), not NaN. Hence why it always return the same number, because your n-1 is always NaN.



quote:
Originally posted by waterbottle
What I'm trying to do first is get the ascii equivalent of the char.
for example, ' ' = 32, 'a' = 97, 'b' = 98, 'A' = 65, '1' = 49.
string.charCodeAt(character position)

eg:
"ab1def".charCodeAt(0) equals 97
"ab1def".charCodeAt(1) equals 98
"ab1def".charCodeAt(2) equals 49

---

To check for certain bits in a number use the bitwise operators.
eg:
3 & 1   will equal 1
3 & 2   will equal 2
1 | 2    will equal 3

---

PS: in the very first reply in this thread, Felu, gave you a link to the JScript documentation. And later on people gave links to that same online documentation. Plenty small examples are given in those docs.

;)

This post was edited on 12-15-2006 at 11:57 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
12-15-2006 11:43 PM
Profile PM Find Quote Report
waterbottle
New Member
*


Posts: 6
Joined: Dec 2006
O.P. RE: RE: [split] What scripts can't do.
quote:
"ab1def".charCodeAt(0) equals 97
"ab1def".charCodeAt(1) equals 98
"ab1def".charCodeAt(2) equals 49

ah, right, I totally misunderstood the example :$

Well, thanks for all the help.
12-16-2006 12:53 AM
Profile E-Mail PM Find Quote Report
« 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