Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Jscript
➜ If else
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Stratus
(25 posts) Bio
|
| Date
| Sun 14 Sep 2003 02:33 AM (UTC) |
| Message
| For some reason I'm trying out JScript, and every time I put an if.. else statement in the script Mushclient gives me an error saying: Syntax error
Line in error:
else
I mean, I even used this as the code to see if it was a mess up in my script.
function OnHello (name, output, wildcards) {
name = wildcards(1);
if(name = "Kyglus")
{
world.send("\"I love you, Kyglus.")
else
world.send("\"I don't think we've ever met, " + name + ".")
end if
} //end
Am I doing something wrong here? |
Trust me, Diet Coke isn't nearly as good as regular.
-Stratus | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #1 on Sun 14 Sep 2003 02:40 AM (UTC) Amended on Sun 14 Sep 2003 02:41 AM (UTC) by David Haley
|
| Message
| Either you use the bracket form of the if or you don't... it seems that there you're opening the if block, but then not closing it.
You should have either:
function OnHello (name, output, wildcards) {
name = wildcards(1);
if(name = "Kyglus")
world.send("\"I love you, Kyglus.")
else
world.send("\"I don't think we've ever met, " + name + ".")
} //end
or
function OnHello (name, output, wildcards) {
name = wildcards(1);
if(name = "Kyglus")
{
world.send("\"I love you, Kyglus.")
}
else
{
world.send("\"I don't think we've ever met, " + name + ".")
}
} //end
Modified to add the following:
You probably also want to terminate your statements with semi-colons, but it's been a while since I've done any J-Script so I don't remember. My bet is that you do, though. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Stratus
(25 posts) Bio
|
| Date
| Reply #2 on Sun 14 Sep 2003 03:05 AM (UTC) |
| Message
| | It still gave me the same error message. |
Trust me, Diet Coke isn't nearly as good as regular.
-Stratus | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #3 on Sun 14 Sep 2003 03:07 AM (UTC) |
| Message
| | Could you paste the exact code you are using this time please? Just to make sure I know exactly what you've got :) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Stratus
(25 posts) Bio
|
| Date
| Reply #4 on Sun 14 Sep 2003 03:09 AM (UTC) |
| Message
| function OnHello (name, output, wildcards) {
name = wildcards(1);
if(name = "Kyglus");
world.send("\"I love you, Kyglus.");
else;
world.send("\"I don't think we've ever met, " + name + ".");
} //end |
Trust me, Diet Coke isn't nearly as good as regular.
-Stratus | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #5 on Sun 14 Sep 2003 03:10 AM (UTC) |
| Message
| | Ah... you don't want those semi-colons after the if and the else. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Stratus
(25 posts) Bio
|
| Date
| Reply #6 on Sun 14 Sep 2003 03:12 AM (UTC) |
| Message
| function OnHello (name, output, wildcards) {
name = world.gettriggerinfo(name, 101);
if(name = "Kyglus")
{
world.send("\"I love you, Kyglus.")
}
else
{
world.send("\"I don't think we've ever met, " + name + ".")
}
} //end
Worked. Apparently wildcards(1) doesn't work with JScript, is there anything like it that does? |
Trust me, Diet Coke isn't nearly as good as regular.
-Stratus | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #7 on Sun 14 Sep 2003 03:13 AM (UTC) Amended on Sun 14 Sep 2003 03:14 AM (UTC) by David Haley
|
| Message
| I don't know about the wildcards(1) thing, but that (the one with brackets) looks syntactically correct. You never want to put semi-colons after an if statement. It works like this:
if ( expression )
BLOCK
else
BLOCK
Where a block is either:
statement
or
{
list of statements
} |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Nick Gammon
Australia (23,169 posts) Bio
Forum Administrator |
| Date
| Reply #8 on Sun 14 Sep 2003 08:14 AM (UTC) |
| Message
|
Quote:
if(name = "Kyglus")
Is this really right? JScript is similar to C, and in C you would write:
Quote:
Apparently wildcards(1) doesn't work with JScript, is there anything like it that does?
Take a look at the exampscript.js file that ships with MUSHclient. It is there to help. You need to use a special function to convert VB arrays to Jscript arrays:
wildcards = VBArray(wildcardsVB).toArray();
name = wildcards [0];
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Dubthach
(47 posts) Bio
|
| Date
| Reply #9 on Tue 16 Sep 2003 04:29 PM (UTC) Amended on Tue 16 Sep 2003 04:30 PM (UTC) by Dubthach
|
| Message
| You're correct Nick.
will always be true, because its assigning "Kyglus" to name.
correct would be
better would be
because then you will get an error immediately if you forget the second = | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
32,938 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top