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
➜ VBscript
➜ Simplifying a Script
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Mike Kilian
(15 posts) Bio
|
| Date
| Sun 13 Jan 2002 05:58 AM (UTC) |
| Message
| I have a bunch of variables that get set and then display the new value by calling a VB script, like this one:
Sub Set_HP (thename, theoutput, arrWildcards)
World.SetVariable "hp", cint(arrWildcards(1))
Call Sub Get_HP
End Sub
And then use a script to only display the value by calling a script like this:
Sub Get_HP (thename, theoutput, arrWildcards)
World.Note " HP: " & World.GetVariable("hp")
End Sub
The first example script is activated by an alias "hp *" where * is an integer, and the second is activated by an alias "hp". I have upwards of a dozen such scripts for my variables, and the number is growing. I know there should be a way to simplify these all into a couple subroutines that will determine what is wanted by what is typed in. So if I want to set my hp variable, or my name variable, etc, they call the same sub(s) to set and/or display. By programing standards, it is a waste of resources to use multiple independant subroutines to display, basically, the same information.
I am a very inexperienced programmer, so please help me trim this down.
Thanks,
Mike
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Sun 13 Jan 2002 06:51 AM (UTC) |
| Message
| There are a few ways you could simplify this ...
The simplest is to use the facility to make a trigger set a variable, eg.
Trigger: hp *
Send: %1
Send to: variable (label is name)
Label: hp
This make the trigger set a variable directly, without scripting.
However if you also want to use aliases to find the hp later on, then you can always test the trigger label in the trigger script. For instance, the trigger label (name) could be the variable you want to set. eg.
Sub Set_variable (thename, theoutput, arrWildcards)
World.SetVariable thename, cint(arrWildcards(1))
Call Sub show_variable (thename, "", "")
End Sub
Sub show_variable (thename, theoutput, arrWildcards)
World.Note " " & thename & ": " & World.GetVariable(thename)
End Sub
In this case you would make a batch of triggers/aliases that use the trigger name to control what variable was set.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | 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.
12,152 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top