Simplifying a Script

Posted by Mike Kilian on Sun 13 Jan 2002 05:58 AM — 2 posts, 12,684 views.

#0
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
Australia Forum Administrator #1
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.