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
➜ Ok, once again, just a test script.
Ok, once again, just a test script.
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Stratus
(25 posts) Bio
|
Date
| Wed 04 Sep 2002 08:59 PM (UTC) |
Message
| I wanted to try out a couple of scripts, first off is there anyway that I could make a script to tell someone the current time like this?
function OnTime (thename, theoutput, thewildcardsVB)
{
var Name
var Time
Name = world.GetTriggerInfo (thename, 101)
Time = ??
world.send ("\"Hello, " + Name + ". The current time is: " + Time + ".")
} //end of OnTime
And second, I wanted to make a test script that would send, "Hello, I will repeat this message X times.", three times. But each time change the X to how many times are left. Is there any way to do this without just writing that three times? |
Trust me, Diet Coke isn't nearly as good as regular.
-Stratus | Top |
|
Posted by
| Shadowfyr
USA (1,791 posts) Bio
|
Date
| Reply #1 on Wed 04 Sep 2002 09:59 PM (UTC) Amended on Wed 04 Sep 2002 10:03 PM (UTC) by Shadowfyr
|
Message
| The first problem... I am not sure.. I believe most scripting engines provide a way to do it, but I haven't a clue how in java.
As for the second problem.. Easiest way would be something like this:
function Repeat(name, output, wildcards)
{
var Wilds = VBArray(wildcards).toArray();
var Rep = int Wilds[1];
if (Rep > 0) {
world.send("\"Hello, I will repeat this message " + Rep + " times.");
Rep = Rep - 1;
Repeat (" "," ",Rep)
}
}
or even easier (and probably more likely to work):
function Repeat(name, output, wildcards)
{
var Wilds = VBArray(wildcards).toArray();
int Rep = int Wilds[1];
int x;
for(x=Rep; x>0; x = x-1)
world.send("\"Hello, I will repeat this message " + x + " times.");
}
Note that there is 'no' certainty this will work. The first one uses recursion, which may not work with scripts. Also, I know next to nothing about proper Jscript, so I can't be sure either one works. ;) lol Both allow you to send the script a number through the alias that determines how many times it will repeat. If you don't give it one, they just exit.
Another method would have been to use a timer and a mushclient variable to do the same thing every second or so,however if your intent is to merely send something a set number of times, without a delay in between, then one of the two above should do it. Assuming I didn't goof something of course. ;) | Top |
|
Posted by
| Stratus
(25 posts) Bio
|
Date
| Reply #2 on Wed 04 Sep 2002 10:36 PM (UTC) |
Message
| Ok, I just tried both of those and neither of them worked. |
Trust me, Diet Coke isn't nearly as good as regular.
-Stratus | Top |
|
Posted by
| Shadowfyr
USA (1,791 posts) Bio
|
Date
| Reply #3 on Wed 04 Sep 2002 10:39 PM (UTC) Amended on Wed 04 Sep 2002 10:40 PM (UTC) by Shadowfyr
|
Message
| I did say I hadn't a clue how to code in Jscript. lol
The structure and concept is more or less right, but I probably got a bit of the syntax wrong. | Top |
|
Posted by
| Stratus
(25 posts) Bio
|
Date
| Reply #4 on Thu 05 Sep 2002 12:50 AM (UTC) |
Message
| Nick help me! lol |
Trust me, Diet Coke isn't nearly as good as regular.
-Stratus | Top |
|
Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
Date
| Reply #5 on Thu 05 Sep 2002 03:58 AM (UTC) |
Message
| Show the date and time:
world.note ("The time is now " + Date().toString ());
Repeating a message:
for (x = 3; x >= 1; x--)
world.note ("Hello, I will repeat this message " + x + " times.");
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shadowfyr
USA (1,791 posts) Bio
|
Date
| Reply #6 on Thu 05 Sep 2002 05:52 AM (UTC) |
Message
| Hmm. Ok. But what did I do wrong in my versions. lol I like to know these things so I don't stick my foot in my mouth the next time around. ;) lol
Would be interesting to know how scripting handles recursion as the very least. | Top |
|
Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
Date
| Reply #7 on Thu 05 Sep 2002 06:28 AM (UTC) |
Message
| The recursion didn't work because on the 2nd call (first recurse) you were no longer passing down an array, here ...
Repeat (" "," ",Rep)
Rep was a scalar, but in the function you called VBArray(wildcards).toArray();
Too complex anyway, for doing something repeatedly. Your other solution was close, this works ...
function Repeat(name, output, wildcards)
{
var Wilds = VBArray(wildcards).toArray();
var Rep = Wilds[0];
var x;
for(x=Rep; x>0; x = x-1)
world.send("\"Hello, I will repeat this message " + x + " times.");
}
I had to get rid of the "int" cast, and change "int" to "var". Also the first array item is 0, not 1.
A smaller version would be:
function Repeat(name, output, wildcards)
{
Wilds = VBArray(wildcards).toArray();
for (x = Wilds[0]; x > 0; x--)
world.send("\"Hello, I will repeat this message " + x + " times.");
}
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Avariel
Portugal (55 posts) Bio
|
Date
| Reply #8 on Thu 05 Sep 2002 03:47 PM (UTC) Amended on Thu 05 Sep 2002 03:49 PM (UTC) by Avariel
|
Message
| or as i rather like to do you can do an up counter FOR cicle instead of a down counter.
function Repeat(thename, theoutput, wildcards)
{
wildcards = VBArray(wildcards).toArray();
times = wildcards [0]
for (i = 1 ; i <= times ; i++)
world.send("\"Hello, I will repeat this message " + times + " times.");
} |
The Avariel Wind Lord | Top |
|
Posted by
| Shadowfyr
USA (1,791 posts) Bio
|
Date
| Reply #9 on Thu 05 Sep 2002 08:19 PM (UTC) |
Message
| Thanks Nick.. Didn't think about the variable being a scalar instead of an array there. Still, wonder if it could work if you did pass the correct type... Hard to say with scripting.
Sorry Avariel, you perhaps didn't read all the thread? He was asking that the <times> in there reflect how many times it was going to continue to repeat. ;) | Top |
|
Posted by
| Avariel
Portugal (55 posts) Bio
|
Date
| Reply #10 on Fri 06 Sep 2002 02:47 PM (UTC) |
Message
| oops i miss the line 'But each time change the X to how many times are left.' :/ sorry guys. |
The Avariel Wind Lord | 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.
29,807 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top