What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Problem with Script - ; required? Where?

Problem with Script - ; required? Where?
Author: Message:
Toneo
Junior Member
**

Avatar
Epic.

Posts: 35
Reputation: 2
28 / Male / Flag
Joined: Jul 2007
O.P. Problem with Script - ; required? Where?
I'm making an AutoMessage script, and it uses random messages. But it stops the script and the debugger has an error:

code:
Error: Expected ';' (code: -2146827284)
       File: AutoMessage.js. Line: 16.


Here is where it finds fault with my script.

code:
int randomNum1 = Math.round(Math.random() * 5 + 1);

switch (randomNum1)
{
case 1 :
randomMsg = "Hello!";
break;

case 2 :
randomMsg = "Hi!";
break;

case 3 :
randomMsg = "Yo";
break;

case 4 :
randomMsg = "Allo";
break;

case 5 :
randomMsg = "Hiya";
break;

case 6 :
randomMsg = "How are you?";
break;
}


Help needed, can't find where to put this ;, or what's wrong with it...
[Image: signature-user=291&back=4&clr=12,102,237&size=80.png]
08-01-2007 07:22 PM
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: Problem with Script - ; required? Where?
quote:
Originally posted by Toneo
int randomNum1
Use var. (or use nothing at all)

JScript's variable declaration does not use data type as declarer (or whatever it's called)
08-01-2007 08:02 PM
Profile PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Problem with Script - ; required? Where?
blah why not do this

code:
var aWordArray = new Array ('Hello!', 'Hi!', 'Yo', 'Allo', 'Hiya', 'How are you?');
Debug.Trace(aWordArray[Math.round(Math.rand() * aWordArray.length + 1)]);

This post was edited on 08-01-2007 at 08:16 PM by matty.
08-01-2007 08:10 PM
Profile E-Mail PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1621
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: Problem with Script - ; required? Where?
quote:
Originally posted by matty
blah why not do this

code:
var aWordArray = new Array ('Hello!', 'Hi!', 'Yo', 'Allo', 'Hiya', 'How are you?');
Debug.Trace(aWordArray[Math.round(Math.rand() * aWordArray.length + 1)]);


I think you actually mean this:
code:
var aWordArray = new Array ('Hello!', 'Hi!', 'Yo', 'Allo', 'Hiya', 'How are you?');
Debug.Trace(aWordArray[Math.floor(Math.rand() * aWordArray.length + 1)]);

And you should use Math.floor() rather than Math.round() anyway, this is because the use of rounding means that the first and last variable have only half of the probability of getting chosen as the others do.  And with matty's code anywa, the addition of 1 would have meant that the array elements would have to start from 1 rather than zero.
[Image: markee.png]
08-01-2007 11:45 PM
Profile PM Find Quote Report
Toneo
Junior Member
**

Avatar
Epic.

Posts: 35
Reputation: 2
28 / Male / Flag
Joined: Jul 2007
O.P. RE: Problem with Script - ; required? Where?
Thanks :) Forgot about arrays and floor(). Didn't know whether to use int or var.

EDIT:
It's still not working. The debugger now says "Error: ; expected" on line 16. I don't understand, there doesn't seem to be a place to put ;. And I don't seem to find anything wrong with my script.

The whole function ChatWnd_ReceiveMessage function.
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageType)
{

if (Origin != Messenger.MyName)
{

if (Messenger.MyStatus != 3)
{
ChatWnd.SendMessage("AutoMessage: I'm busy right now.");
}

var wordArray = new Array ('Hello!', 'Hi!', 'Yo', 'Allo', 'Hiya', 'Why, Hello!');
var randomMsg = wordArray[Math.floor(Math.rand() * wordArray.length)];

switch (Message.toUpperCase())
{
case "HI" :
ChatWnd.SendMessage(randomMsg);
break;

case "HI!" :
ChatWnd.SendMessage(randomMsg);
break;

case "LO" :
ChatWnd.SendMessage(randomMsg);
break;

case "\'LO" :
ChatWnd.SendMessage(randomMsg);
break;

case "HIYA" :
ChatWnd.SendMessage(randomMsg);
break;

case "HIYA!" :
ChatWnd.SendMessage(randomMsg);
break;

case "HELLO!" :
ChatWnd.SendMessage(randomMsg);
break;

case "HELLO" :
ChatWnd.SendMessage(randomMsg);
break;

case "YO" :
ChatWnd.SendMessage(randomMsg);
break;

case "YO." :
ChatWnd.SendMessage(randomMsg);
break;

case "YO!" :
ChatWnd.SendMessage(randomMsg);
break;

case "ALLO" :
ChatWnd.SendMessage(randomMsg);
break;

case "ALLO!" :
ChatWnd.SendMessage(randomMsg);
break;
}

}

}


This post was edited on 08-02-2007 at 08:50 AM by Toneo.
[Image: signature-user=291&back=4&clr=12,102,237&size=80.png]
08-02-2007 08:41 AM
Profile E-Mail PM Find Quote Report
LifelesS
Full Member
***


Posts: 115
Reputation: 4
31 / Male / Flag
Joined: Dec 2006
RE: Problem with Script - ; required? Where?
I try to run the code myself, it just gave me an error on the:
var randomMsg = wordArray[Math.floor(Math.rand() * wordArray.length)];

Says object doesn't support this property or method, anyway, shouldn't it be easier to turn the array into an enumerator and use a for loop?

something like this:

code:
        var e = new Enumerator(wordArray)
        for(; !e.atEnd(); e.moveNext())
        {
            var word = e.item();
            if(Message.toUpperCase() == word)
            {
                ChatWnd.SendMessage(randomMsg);
                break;
            }
        }

- you had this to toUppercase() instead of toUpperCase() also

That should work, at least works for me:)
You just need to add all other things to the array and your set to go ;)
And if you're going to use many words, you can put them on a .txt file and load it to an array using split() after readall()
Best Regards,
Joćo Godinho
08-02-2007 12:00 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Problem with Script - ; required? Where?
Untested but should work

code:
var wordArray = new Array ('Hello!', 'Hi!', 'Yo', 'Allo', 'Hiya', 'Why, Hello!');
var receivedWordArray = new Array ('HI', 'HI!', 'LO', '\'LO', 'HIYA', 'HELLO!', 'HELLO', 'YO.', 'YO!', 'YO', 'ALLO!', 'ALLO');

function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageType) {
    if (Origin != Messenger.MyName) {
        if (Messenger.MyStatus != 3) {
            ChatWnd.SendMessage('AutoMessage: I\'m busy right now.');
            return false;
        }
        var randomMsg = wordArray[Math.floor(Math.rand() * wordArray.length)];
        for (var i in receivedWordArray) {
            if (Message.toUperCase() === receivedWordArray[i]) {
                ChatWnd.SendMessage(randomMsg);
            }
        }
    }
}

Also please note that this can cause infinite loops and you should take precautions when sending messages.

Best way is to store the Message you send in an object then compare the message if it is the same then disregard it.

This post was edited on 08-02-2007 at 12:46 PM by matty.
08-02-2007 12:40 PM
Profile E-Mail PM Find Quote Report
LifelesS
Full Member
***


Posts: 115
Reputation: 4
31 / Male / Flag
Joined: Dec 2006
RE: Problem with Script - ; required? Where?
matty way is simpler I think, and instead of using all that things in the array ('YO', 'YO!') you could use a Regular Expression.
Best Regards,
Joćo Godinho
08-02-2007 12:43 PM
Profile E-Mail PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: Problem with Script - ; required? Where?
I think this will work even better

code:
var wordArray = new Array ('Hello!', 'Hi!', 'Yo', 'Allo', 'Hiya', 'Why, Hello!');
var receivedWordArray = new Array ('HI', 'HI!', 'LO', '\'LO', 'HIYA', 'HELLO!', 'HELLO', 'YO.', 'YO!', 'YO', 'ALLO!', 'ALLO');
var re = RegExp("\b"+receivedWordArray.join("\b|\b")+"\b","i");

function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageType) {
    if (Origin != Messenger.MyName) {
        if (Messenger.MyStatus != 3) {
          ChatWnd.SendMessage('AutoMessage: I\'m busy right now.');
          return false;
        }
        var randomMsg = wordArray[Math.floor(Math.rand() * wordArray.length)];
        if (re.test(Message)){
          ChatWnd.SendMessage(randomMsg);
        }
    }
}

Credits to markee for the regex

This post was edited on 08-02-2007 at 01:06 PM by Ezra.
[Image: 1-0.png]
             
08-02-2007 01:03 PM
Profile PM Web Find Quote Report
LifelesS
Full Member
***


Posts: 115
Reputation: 4
31 / Male / Flag
Joined: Dec 2006
RE: RE: Problem with Script - ; required? Where?
quote:
Originally posted by matty

Also please note that this can cause infinite loops and you should take precautions when sending messages.

Best way is to store the Message you send in an object then compare the message if it is the same then disregard it.


That's y I used the break; inside the if, so when it founds the word quits for loop.
Best Regards,
Joćo Godinho
08-02-2007 01:15 PM
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