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
➜ Making a increasing number script
Making a increasing number script
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| VIVIX
(16 posts) Bio
|
Date
| Wed 20 Nov 2002 10:31 PM (UTC) |
Message
| I'm trying to make a script that will start with a number and increase by one after a certain trigger is set off and send something to the world with the new number repeatedly. | Top |
|
Posted by
| Magnum
Canada (580 posts) Bio
|
Date
| Reply #1 on Thu 21 Nov 2002 02:45 AM (UTC) |
Message
| First, create a script subroutine to set the counter:
Sub Set_Counter (AliasName, AliasLine, Wildcards)
World.SetVariable "Mystery_Counter", Wildcards(1)
End Sub
Put that in your script file.
Next add the alias that calls that subroutine:
<aliases>
<alias
name="Set_Counter"
script="Set_Counter"
match="^setcounter (\d*)$"
enabled="y"
regexp="y"
ignore_case="y"
>
</alias>
</aliases>
(You can copy that into your windows clipboard by highlighting it and pressing CTRL-C, then going to the MUSHclient Alias screen and clicking the "PASTE" button)
Next, add the subroutine that will increase the counter value by one:
Sub Mysterious_Counter (TriggerName, TriggerLine, Wildcards)
World.SetVariable "Mystery_Counter", CINT(World.GetVariable("Mystery_Counter")) + 1
World.LogSend "Mystery_Counter: " & World.GetVariable("Mystery_Counter")
End Sub
Finally, create the trigger for the line you want to match on. Give the trigger a name in the appropriate field, and in the field labelled "Script", enter "Mysterious_Counter". You are done. |
Get my plugins here: http://www.magnumsworld.com/muds/
Constantly proving I don't know what I am doing...
Magnum. | Top |
|
Posted by
| VIVIX
(16 posts) Bio
|
Date
| Reply #2 on Thu 21 Nov 2002 03:33 AM (UTC) |
Message
| Woah, that's hightech stuff. When I say repeatedly I mean like it'll loop, sorry I didn't say that the first time. I have more time now so I can explain more. First off, I can't get that to work. 1) I can't seem to save my notepad file as a .jvs file so that MUSHclient sees it. 2) When you made that alias, I can't just go to the alias tab and press print.
What I meant to say in the first post was, I want to make a script that'll send goto 1000, then when the trigger is set off it'll send goto 1001 and then when the trigger is set off again it'll send goto 1002.... and will continue until I stop it.
Thanks for the help though Magnum. | Top |
|
Posted by
| Magnum
Canada (580 posts) Bio
|
Date
| Reply #3 on Thu 21 Nov 2002 04:17 PM (UTC) Amended on Thu 21 Nov 2002 04:30 PM (UTC) by Magnum
|
Message
| Ok...
First off, the script I am providing to you is Visual Basic Script. I don't know the other languages well enough to write in them, sorry.
You should always use the latest version of MUSHclient whenever possible, unless you have a very specific reason not to. The newer versions allow you to "COPY" or "PASTE" alias and trigger code via buttons, on the particular screen that lists the aliases and triggers.
A script file is essentially a text file. It simply has an extension label indicating the language. For example, you might name your MUSHclient script file "MyScript.vbs". You can open up windows notepad to edit such a file. You can also ask MUSHclient to edit the file for you as well.
First things first: With your world open/connected, press CTRL-SHIFT-6 to open your scripting menu. Select the scripting language for your main script file. Personally, I use "VBscript". Make sure the "Enable script" checkbox is checked. Next, Use the "Script File" field to point to your script file. If you have an existing file, this is where you should point to it. Even if you don't have a script yet, you can provide the path and name here, and MUSHclient will create the file for you.
Once you have those steps complete, you can click on the "Edit Script" button that is also on this screen. This will allow you to edit your script file directly in MUSHclient's editor.
Now, all of that aside... There is a special trick to looping some activity in MUSHclient. You generally don't want the script to loop something repeatedly without returning control back to MUSHclient. When a script is running, everything else is on hold. MUSHclient does not process any input/output while it's busy running a script...
Therefor... If you want to loop an activity, you should do so by means of triggers. That is, build triggers to fire repeatedly, thereby creating your loop for you. Don't just have your script go in an endless circle that can never be interupted. Here's an example doing it properly:
- MUSHclient trigger detects room title line.
- The trigger calls a script subroutine.
- The subroutine performs calculations, and SENDs a line telling the MUD to move you to another room.
- Back to first step, the trigger detects room title.
Now, even in a situation like this, the trigger-calling-script loop may execute so fast that you can't really stop it when you want. By the time your action to stop the loop gets executed, it may have went through many more iterations that you intended.
There are two methods I would recommend for a project like this:
- Create an alias to set/reset the counter-loop.
- Create Trigger(s) to perform the looping (calls script).
- Create an alias to stop the loop.
- In the script, use a stalling method of sending input, to give you time to stop the loop. (World.DoAfter for example - wait a couple of seconds before sending)
OR:
- Create an alias to set/reset the counter-loop.
- Create a "next" alias to perform the next iteration (calls script to execute next step).
With the second method, you might just keep typing "Next" over and over again. (Since it remains in the input box, you don't even have to type it, you just press "Enter" over and over again to repeat the last input). Of course, to stop, you just start doing whatever else you want.
So... I suggest you pick one of those methods before proceeding.
I just noticed that this is the JScript forum. Sorry. You must obviously prefer that as your scripting language. Most of what I just said above still applies. Instead of using a filename extention of .VBS (Visual Basic Script), you would instead use the one for JScript, which it think is .JS .
Once your decision is made, I'm sure someone else here would be willing to help you implement that method. |
Get my plugins here: http://www.magnumsworld.com/muds/
Constantly proving I don't know what I am doing...
Magnum. | Top |
|
Posted by
| VIVIX
(16 posts) Bio
|
Date
| Reply #4 on Thu 21 Nov 2002 09:24 PM (UTC) |
Message
| Well, Jscript isn't my preferred scripting language. I just figured that it would be easier to learn than vbscript because I'm also trying to learn C/C++ right now. Do you think you could help me make it in vbscript since you are obviously so good at it. I tried to make your script work again, I downloaded the latest version of MUSHclient and copy and pasted the alias into the alias tab, but what do I have to type to set the counter? | Top |
|
Posted by
| Shadowfyr
USA (1,791 posts) Bio
|
Date
| Reply #5 on Fri 22 Nov 2002 05:49 AM (UTC) |
Message
| Since you plan to be able to 'turn it off' I would suggest a small modification to things:
<aliases>
<alias
name="Set_Counter"
script="Set_Counter"
match="^setcounter (\d*)$"
enabled="y"
regexp="y"
ignore_case="y"
>
</alias>
<alias
name="Stop_Counter"
script="Stop_Counter"
match="^stopcount"
enabled="y"
regexp="y"
ignore_case="y"
>
</alias>
</aliases>
Sub Set_Counter (AliasName, AliasLine, Wildcards)
World.SetVariable "Mystery_Counter", Wildcards(1)
World.EnableTrigger "Count_Trig", vbTrue
End Sub
Sub Stop_Counter (AliasName, AliasLine, Wildcards)
World.EnableTrigger "Count_Trig", vbFalse
End Sub
Sub Mysterious_Counter (TriggerName, TriggerLine, Wildcards)
World.LogSend "Mystery_Counter: " & World.GetVariable ("Mystery_Counter")
World.SetVariable "Mystery_Counter", CINT(World.GetVariable("Mystery_Counter")) + 1
End Sub
By giving the trigger that calls it the name Count_Trig, setting the value will result in the trigger begining to work, while stopcount will shut it down. ;) The alias Magnum gave you uses the command 'setcounter #', where # is where it will start counting. I also changed the actual counting bit, since the way Magnum had it, the count would increment 'before' it was sent. i.e. If you gave it 1000, it would retrieve 1000, add 1, then send 1001. Oops!
Basically you just turn it on like:
setcounter 1000
and off with:
stopcount
;) | 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.
19,669 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top