Whats wrong with this? |
Author: |
Message: |
Hengy
Junior Member
Posts: 16
Joined: Jul 2006
|
O.P. Whats wrong with this?
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
|
|
07-22-2006 08:00 PM |
|
|
Mnjul
forum super mod
plz wub me
Posts: 5396 Reputation: 58
– / /
Joined: Nov 2002
Status: Away
|
RE: Whats wrong with this?
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."
}
This post was edited on 07-22-2006 at 08:10 PM by Mnjul.
|
|
07-22-2006 08:07 PM |
|
|
Weyzza
Veteran Member
SoCal sunset > *
Posts: 1170 Reputation: 29
– / / –
Joined: May 2003
|
RE: Whats wrong with this?
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
This post was edited on 07-22-2006 at 08:13 PM by Weyzza.
Registered 7853 days, 3 hours, 4 minutes, 1 second ago.
Happy Birthday, WDZ
|
|
07-22-2006 08:07 PM |
|
|
Hengy
Junior Member
Posts: 16
Joined: Jul 2006
|
O.P. RE: Whats wrong with this?
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...
|
|
07-22-2006 08:24 PM |
|
|
Weyzza
Veteran Member
SoCal sunset > *
Posts: 1170 Reputation: 29
– / / –
Joined: May 2003
|
RE: Whats wrong with this?
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
This post was edited on 07-22-2006 at 08:34 PM by Weyzza.
Registered 7853 days, 3 hours, 4 minutes, 1 second ago.
Happy Birthday, WDZ
|
|
07-22-2006 08:27 PM |
|
|
Hengy
Junior Member
Posts: 16
Joined: Jul 2006
|
O.P. RE: Whats wrong with this?
Go easy! Im a beginner...
and it still doesn't work...
|
|
07-22-2006 08:33 PM |
|
|
Aeryn
Full Member
Posts: 230 Reputation: 28
– / / –
Joined: Jun 2005
Status: Away
|
RE: Whats wrong with this?
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.
This post was edited on 07-22-2006 at 08:52 PM by Aeryn.
|
|
07-22-2006 08:40 PM |
|
|
Hengy
Junior Member
Posts: 16
Joined: Jul 2006
|
O.P. RE: Whats wrong with this?
Thanks! It works!
|
|
07-22-2006 08:53 PM |
|
|
Aeryn
Full Member
Posts: 230 Reputation: 28
– / / –
Joined: Jun 2005
Status: Away
|
RE: Whats wrong with this?
No problem, glad it works now.
|
|
07-22-2006 09:00 PM |
|
|
Hengy
Junior Member
Posts: 16
Joined: Jul 2006
|
O.P. RE: Whats wrong with this?
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
|
|
07-22-2006 10:33 PM |
|
|
Pages: (3):
« First
[ 1 ]
2
3
»
Last »
|
|