Shoutbox

[split] What scripts can't do. - 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: [split] What scripts can't do. (/showthread.php?tid=69494)

RE: What scripts can't do. by waterbottle on 12-13-2006 at 09:18 PM

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...


RE: What scripts can't do. by Felu on 12-14-2006 at 10:30 AM

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/
RE: What scripts can't do. by J-Thread on 12-14-2006 at 10:58 AM

&& 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...


RE: [split] What scripts can't do. by Mnjul on 12-14-2006 at 03:07 PM

You need to use charCodeAt method, waterbottle :)


RE: [split] What scripts can't do. by waterbottle on 12-15-2006 at 10:30 PM

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? :)
RE: [split] What scripts can't do. by Plik on 12-15-2006 at 11:06 PM

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
RE: [split] What scripts can't do. by waterbottle on 12-15-2006 at 11:18 PM

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.


RE: [split] What scripts can't do. by Plik on 12-15-2006 at 11:37 PM

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
RE: [split] What scripts can't do. by CookieRevised on 12-15-2006 at 11:43 PM

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.

;)
RE: RE: [split] What scripts can't do. by waterbottle on 12-16-2006 at 12:53 AM

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.