Shoutbox

Whats wrong with this? - 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: Whats wrong with this? (/showthread.php?tid=63807)

Whats wrong with this? by Hengy on 07-22-2006 at 08:00 PM

I am a beginning scripter... I have had limited experience in BASIC, VB, C#. I am just trying to learn the jscript language...

Does anyone know whats wrong with this script?

code:
function OnEvent_ChatWndSendMessage(Wnd,Msg) {
    if(Msg == "!picknum") {
return "Pick a number between 1 and 100";
var rndnumber = Math.random() * 100;
}

function OnEvent_ChatWndReceiveMessage(Wnd,Msg,1) {
if(Msg == rndnumber) {
return rndnumber + "was the correct number."
}

Thanks
RE: Whats wrong with this? by Mnjul on 07-22-2006 at 08:07 PM

Your OnEvent_ChatWndReceiveMessage has incorrect parameters.

The first parameter is Chat window, yes, but the second is the name of the users sending the message, while the third one being the message itself. Finally, MessageKind is a variable and you can't not set 1 for that :)

So your codes should look like:

code:
function OnEvent_ChatWndReceiveMessage(Wnd,Sender,Msg,MsgKind){
    if(Msg == rndnumber) {
    return rndnumber + "was the correct number."
}


RE: Whats wrong with this? by Weyzza on 07-22-2006 at 08:07 PM

quote:
Originally posted by Hengy
if(Msg == "!picknum") {
return "Pick a number between 1 and 100";
var rndnumber = Math.random() * 100;
}
You should not use return there.

Keyword "return" exits from the current function and returns a value from that function (form here)

And you have extra curly brackets, too :tongue:
RE: Whats wrong with this? by Hengy on 07-22-2006 at 08:24 PM

so i've got this now, but it still doen't work...
(please be patient with me...:$)

code:
function OnEvent_ChatWndSendMessage(Wnd,Msg) {
    if(Msg == "!picknum") {
    return Begin();
}

function Begin() {
    var rndnumber = Math.random() * 100;
    return "Pick a number between 1 and 100.";
}

function OnEvent_ChatWndReceiveMessage(Wnd,Sender,Msg,MsgKind){
if(Msg == rndnumber) {
    return rndnumber + "was the correct number.";
}


I am afriad I don't see the extra brackets... :huh:
RE: Whats wrong with this? by Weyzza on 07-22-2006 at 08:27 PM

quote:
Originally posted by Hengy
I am afriad I don't see the extra brackets...
What about the ones after each if statement?

Edit: I'm sorry if I sound harsh, but that's truly not my intention :p
RE: Whats wrong with this? by Hengy on 07-22-2006 at 08:33 PM

Go easy! Im a beginner...
and it still doesn't work...:$


RE: Whats wrong with this? by Aeryn on 07-22-2006 at 08:40 PM

It's easier to see bracket mismatches if you put each bracket on a line by itself and indent your code.


code:
function OnEvent_ChatWndReceiveMessage(Wnd,Sender,Msg,MsgKind)
{
  if(Msg == rndnumber)
  {
    return rndnumber + "was the correct number.";
  }


as you can see there's a missing bracket for the function header.

so it should be like this:

code:
function OnEvent_ChatWndReceiveMessage(Wnd,Sender,Msg,MsgKind)
{
  if(Msg == rndnumber)
  {
    return rndnumber + "was the correct number.";
  }
}


Edit: actually it's the exact same thing with the first section of your code too:

code:
function OnEvent_ChatWndSendMessage(Wnd,Msg) {
if(Msg == "!picknum") {
return Begin();
}

there should be one more bracket in the end again.
RE: Whats wrong with this? by Hengy on 07-22-2006 at 08:53 PM

Thanks! It works!


RE: Whats wrong with this? by Aeryn on 07-22-2006 at 09:00 PM

No problem, glad it works now. :)


RE: Whats wrong with this? by Hengy on 07-22-2006 at 10:33 PM

Sorry to bother u all again... but in this thing of code, when I say "!an", it come back "undefined"...

code:
function OnEvent_ChatWndSendMessage(Wnd,Msg)
{
if(Msg == "!pick")
    {
    var rndnumber = Math.floor(Math.random()*5);
    return "Pick a number between 0 and 4";
    }
if(Msg == "!an")
    {
    return rndnumber + "was the correct number.";
    }
}


Thanks
RE: Whats wrong with this? by ShawnZ on 07-22-2006 at 10:43 PM

it returns undefined because you never set "rndnumber" if the Msg is !an.


RE: Whats wrong with this? by Hengy on 07-22-2006 at 10:50 PM

I don't really get what your trying to tell me... srry


RE: Whats wrong with this? by ShawnZ on 07-22-2006 at 10:51 PM

if(Msg == "!an") {
     return rndnumber + "was the correct number.";
}


you don't set rndnumber anywhere there.


RE: Whats wrong with this? by Hengy on 07-22-2006 at 10:53 PM

Srry, I didn't know what u meant :-s
It works now though, Thanks


RE: Whats wrong with this? by cloudhunter on 07-23-2006 at 12:10 AM

Can't see how... But hey, your script. It is a bit sloppy coding though...

Cloudy


RE: Whats wrong with this? by Hengy on 07-23-2006 at 01:24 AM

(yes, it's me again... 8-|)
so i've got this:

code:
var rndnumber = Math.floor(Math.random()*26);

function OnEvent_ChatWndSendMessage(Wnd,Msg)
{
    if(Msg == "!pick")
        {
        return "Pick a number between 0 and 25";
        }
if(Msg == rndnumber)
        {
        return Command_Win();
        }

function OnEvent_ChatWndReceiveMessage(Wnd,Sender,Msg,MsgKind)
{
    if(Msg == rndnumber)
        {
        return Command_Win();
        }
    }
}

function Command_Win()
{
return rndnumber + " was the correct number! ";
}

But the random number is only generated once, and if you try this script again without modifying the script (exiting the conv doesn't work) then the random number is still the same... Is there anyway to get around this?
RE: RE: Whats wrong with this? by mickael9 on 07-23-2006 at 01:45 AM

quote:
Originally posted by Hengy
(yes, it's me again... 8-|)
so i've got this:

code:
var rndnumber = Math.floor(Math.random()*26);

function OnEvent_ChatWndSendMessage(Wnd,Msg)
{
    if(Msg == "!pick")
        {
        return "Pick a number between 0 and 25";
        }
if(Msg == rndnumber)
        {
        return Command_Win();
        }

function OnEvent_ChatWndReceiveMessage(Wnd,Sender,Msg,MsgKind)
{
    if(Msg == rndnumber)
        {
        return Command_Win();
        }
    }
}

function Command_Win()
{
return rndnumber + " was the correct number! ";
}

But the random number is only generated once, and if you try this script again without modifying the script (exiting the conv doesn't work) then the random number is still the same... Is there anyway to get around this?


code:
var rndnumber;

function OnEvent_ChatWndSendMessage(Wnd,Msg)
{
    if(Msg == "!pick")
    {
        rndnumber = Math.floor(Math.random()*26);
        return "Pick a number between 0 and 25";
    }
    if(Msg == rndnumber)
    {
        return Command_Win();
    }
   
    function OnEvent_ChatWndReceiveMessage(Wnd,Sender,Msg,MsgKind)
    {
        if(Msg == rndnumber)
        {
            return Command_Win();
        }
    }
}

function Command_Win()
{
    rndnumber = null;
    return rndnumber + " was the correct number! ";
}
:D
RE: Whats wrong with this? by cloudhunter on 07-23-2006 at 01:54 AM

Simple :)

code:
var rndnumber;
function OnEvent_ChatWndSendMessage(Wnd,Msg)
{
if(Msg == "!pick")
{
rndnumber = Math.floor(Math.random()*26);
return "Pick a number between 0 and 25";
}
}


function OnEvent_ChatWndReceiveMessage(Wnd,Sender,Message,MsgKind)
{
if(Message == rndnumber)
{
Command_Win(Wnd);
}
}

function Command_Win(Wnd)
{
Wnd.SendMessage(rndnumber + " was the correct number! ");
}

This code is fully working, when you send !pick it tells you AND the contact "Pick a number between 0 and 25". When you or the contact get the number right it now says you have won :) It generates the random number each time you say !pick.

Cloudy

Edit: Beaten to it, but my alteration works correctly ;) It now picks wins from both the contact and the sender, as you don't need both send and recieve for that as any messages you send count as recieved messages aswell. It also now returns the win to the conversation window properly once someone gets it right. Before what it would have done was alter the recieved message on your end.
RE: Whats wrong with this? by Hengy on 07-23-2006 at 02:16 PM

WOW! Thanks alot! :D


RE: RE: Whats wrong with this? by mickael9 on 07-23-2006 at 06:02 PM

quote:
Originally posted by cloudhunter
Simple :)

code:
var rndnumber;
function OnEvent_ChatWndSendMessage(Wnd,Msg)
{
if(Msg == "!pick")
{
rndnumber = Math.floor(Math.random()*26);
return "Pick a number between 0 and 25";
}
}


function OnEvent_ChatWndReceiveMessage(Wnd,Sender,Message,MsgKind)
{
if(Message == rndnumber)
{
Command_Win(Wnd);
}
}

function Command_Win(Wnd)
{
Wnd.SendMessage(rndnumber + " was the correct number! ");
}

This code is fully working, when you send !pick it tells you AND the contact "Pick a number between 0 and 25". When you or the contact get the number right it now says you have won :) It generates the random number each time you say !pick.

Cloudy

Edit: Beaten to it, but my alteration works correctly ;) It now picks wins from both the contact and the sender, as you don't need both send and recieve for that as any messages you send count as recieved messages aswell. It also now returns the win to the conversation window properly once someone gets it right. Before what it would have done was alter the recieved message on your end.


try to say the number twice :P
RE: Whats wrong with this? by cloudhunter on 07-23-2006 at 06:06 PM

I was aware of that ;) I actually fixed it in my copy of the code. But here is the little fix that is needed:

code:
var rndnumber;
function OnEvent_ChatWndSendMessage(Wnd,Msg)
{
if(Msg == "!pick")
{
rndnumber = Math.floor(Math.random()*26);
return "Pick a number between 0 and 25";
}
}


function OnEvent_ChatWndReceiveMessage(Wnd,Sender,Message,MsgKind)
{
if(Message == rndnumber)
{
Command_Win(Wnd);
}
}

function Command_Win(Wnd)
{
Wnd.SendMessage(rndnumber + " was the correct number! ");
rndnumber = null;
}

Cloudy