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
➜ Pretty new to this - general help
|
Pretty new to this - general help
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Xinphinity
USA (26 posts) Bio
|
| Date
| Thu 04 Apr 2002 11:27 PM (UTC) |
| Message
| I am playing the game Dragonrealms and would like some basic advice on making the VBS scripting work in MUSHClient. (Looks really really cool btw...:))
I sort of understand triggers but I am unclear as to how I would capture MUD text into a variable.
Say my MUD output looked like:
Primary Magic: 81 35.04% thoughtful
And I wanted to capture the word 'thoughtful' to a variable, and then act on this variable in script...
How would I do this?
Thanks for any help...
Xin | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Fri 05 Apr 2002 12:49 AM (UTC) |
| Message
| Triggers usually have a "fixed bit" (to help identify the line in question) and some "variable bits" - which are what you want to find.
In your case I guess the numbers and the word "thoughtful" are the variables, so I would make a trigger like this:
Primary Magic: * *% *
That is three asterisks because we have three wildcards (the number 81, the percentage 35.04 and the word "thoughtful".
Next you want to call a script, and act on the word in the 3rd wildcard, something like this (OnMagic is the script name) ...
sub OnMagic (strName, strLine, aryWildcards)
dim theword
theword = aryWildcards (3) ' get 3rd wildcard
if theword = "thoughtful" then
world.send "sigh"
end if
end sub
This example just sends "sigh" if the word was "thoughtful" but you could of course do something else there. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Xinphinity
USA (26 posts) Bio
|
| Date
| Reply #2 on Fri 05 Apr 2002 04:48 PM (UTC) |
| Message
| That was a great help thanks much.
I have another question...;)
Is there any way to delay code execution while a timer is in progress?
Here is an example of what I am trying to do.
In DragonRealms, skills can be worked effectively as the mental state of the character changes from 'clear' meaning they are not learning the skill, to 'mind locked' meaning they are unable to effectively process more learning on that skill. So, the goal for my code is to look at a skill, determine its state, and if it is not mind locked, execute a routine that works the skill until it is. At that point, the code would check another skill, then another, etc.
To do this, I am placing the mental states for the skills into variables. Then, I am executing code that would hopefully do something like this.
DO WHILE RTRIM(World.GetVariable("PrimaryMagicSkill")) <> "Mind Locked"
World.AddTimer "PrepPsy", 0, 0, 1, "Prep Psy 1", eOneShot, ""
world.EnableTimer "PrepPsy", TRUE
World.AddTimer "CastTimer", 0, 0,15, "Cast", 5, ""
world.EnableTimer "CastTimer", TRUE
LOOP
Now, clearly this code will not work. The idea though, is that say for my magic skill, I must prepare a spell, wait until it is ready then cast it. Then i need to recheck the skill and if it is still not mind locked, i need to repeat the routine.
What is happening is I cannot get a loop going that accomplishes this, if i had a 'delay' function, or something that would wait a specified period i could do it, but using timers is just not working.
Any ideas?
Nothing I do is ever easy...
~Xin | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Fri 05 Apr 2002 10:57 PM (UTC) |
| Message
| For a start, you can do this in one line:
world.AddTimer "PrepPsy", 0, 0, 1, "Prep Psy 1", eOneShot, ""
world.EnableTimer "PrepPsy", TRUE
You can combine the flags to make an enabled timer:
world.AddTimer "PrepPsy", 0, 0, 1, "Prep Psy 1", eOneShot + eEnabled, ""
I'm not sure why you wait 1 second before preparing the spell, why not just do this ...
world.send "Prep Psy 1"
world.addTimer "CastTimer", 0, 0,15, "Cast", 5, ""
As for your main question, it would be simple to just set up a timer that fires, say, every 30 seconds (not a one-shot, but continuous), that checks to see if it can prepare and cast any spells.
I'm not sure how you know what stage you are up to, but the timer could fire off a message to find the status of the current spell, and you then use a trigger to match on the response. If the status is not "mind locked" then the trigger could do the above code (prepare and cast the spell).
If the status *is* "mind locked" then it could move on to the next spell in the list.
You could make the trigger "omit from output" so it doesn't clutter up the screen. You might modify the trigger so it changes itself to not "omit from output" after it has fired, so that you can use the same command, and see the output, if you wanted to manually.
Once you have learnt all the spells the timer/trigger might disable the 30-second timer, and then you re-enable it when there is another spell to be learnt. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Magnum
Canada (580 posts) Bio
|
| Date
| Reply #4 on Sat 06 Apr 2002 05:43 PM (UTC) Amended on Sat 06 Apr 2002 05:50 PM (UTC) by Magnum
|
| Message
| My question is, why are you using a DO WHILE LOOP? (As opposed to an IF THEN)?
You should know that while script is executing, MUSHclient is effectively held up from processing any MUD output. It will finish running any script routines that are active, then return to process MUD output.
You should probably simply use an IF statement:
IF TRIM(World.GetVariable("PrimaryMagicSkill")) <> "Mind Locked" THEN
World.AddTimer "PrepPsy", 0, 0, 1, "Prep Psy 1", eOneShot + eEnabled, ""
World.AddTimer "CastTimer", 0, 0,15, "Cast", 5 + eEnabled, ""
End IF
If you are waiting for "PrimaryMagicSkill" to change while you are in the LOOP, it won't happen. The MUD will not process any output, thus no other triggers will fire, thus the value will not change (Since you set it with a trigger, right?).
Indeed... If this is a copy of the WHOLE subroutine: If you enter this loop while the value is <> "Mind Locked", you will put MUSHclient into a continuous loop that will never be broken, effectively locking up the client!
What you probably want to do, is use an if statement. Your triggers should act 'as the loop'... by calling the subroutine repeatedely, whenever the status of whatever changes...
(Amended for typos) |
Get my plugins here: http://www.magnumsworld.com/muds/
Constantly proving I don't know what I am doing...
Magnum. | | Top |
|
| Posted by
| Xinphinity
USA (26 posts) Bio
|
| Date
| Reply #5 on Mon 08 Apr 2002 04:44 PM (UTC) |
| Message
| Thanks for your help folks, still working on that particular issue. Its a bit tough, DR (Dragonrealms) has some funky systems that require some special handling. I think I can make this happen but right now I have two issues I cant get around.
The first one is, when I try to get a timers 'script' entry to execute the sub routine "CheckPrimary" and execute this code:
Sub CheckPrimary
World.Send "exp primary"
if RTRIM(World.GetVariable("PrimaryMagicSkill")) <> "Mind Locked" THEN
World.AddTimer "PrepPsy", 0, 0, 1, "Prep Psy 1", 5, ""
world.EnableTimer "PrepPsy", TRUE
World.AddTimer "CastTimer", 0, 0,15, "Cast", 5, ""
World.EnableTimer "CastTimer", TRUE
Else
World.EnableTimer "PrimaryMagicTimer", FALSE
end if
End Sub
I get the error message:
Wrong number of arguments for subroutine when processing timer...
And the sub does not get run.
Okay issue two is...
Say I have a VBS function OR sub for instance
Sub GreetPlayer(CharName)
World.Send "Hello there, " & CharName
End Sub
The input var "CharName" is *always* empty when I invoke the sub from the command using /GreetPlayer players
However, if I fail to specify a inpur var, by sending just /GreetPlayer, I do get an error.
Any ideas on these two?
~Xin | | Top |
|
| Posted by
| Xinphinity
USA (26 posts) Bio
|
| Date
| Reply #6 on Mon 08 Apr 2002 04:46 PM (UTC) |
| Message
| Guys...
Disregard the second part of that regarding input var...duh...just got that one figured out.
~Xin | | Top |
|
| Posted by
| Magnum
Canada (580 posts) Bio
|
| Date
| Reply #7 on Mon 08 Apr 2002 10:13 PM (UTC) |
| Message
| You are actually running into a similar problem on both counts.
When a subroutine is called from an alias, or from a trigger, the alias/trigger attempts to pass three arguments to the subroutine:
SourceCallingName - The label of the alias or trigger making the call.
TheOutput - From a trigger, the whole line which caused the trigger to fire, from alias, I assume 'Empty'.
TheWildcards - an array of all the wildcards.
So, typically, you'll have a subroutine like this:
Sub Display_Something (SourceName, TheOutput, arrWildcards)
'Do something
End Sub
This subroutine is expecting three arguments, which is required if you want to call the subroutine from an alias or trigger.
Now, if you call a subroutine from a timer, that's slightly different, but in the same realm:
A timer tries to pass along just one argument. It's a Error/Status code, that indicates either success, or a code representing an error. (Read the help for that function to learn more).
So, a typical subroutine that will be called by a timer might look like this:
Sub OnTimerFired (TimerErrorCode)
'Do something
End Sub
There's more to be learned about arrWildcards above, such as what arrWildcards(0) holds...
I think it holds all the wildcards together in one string, but at the moment, I'm not quite sure. :)
Regardless, arrWildcards(1) will be the first wildcard, arrWildcards(2) will be the second, etc... |
Get my plugins here: http://www.magnumsworld.com/muds/
Constantly proving I don't know what I am doing...
Magnum. | | Top |
|
| Posted by
| Xinphinity
USA (26 posts) Bio
|
| Date
| Reply #8 on Mon 08 Apr 2002 10:34 PM (UTC) |
| Message
| Perfect thanks, that solves a lot.
~Xin | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #9 on Tue 09 Apr 2002 12:12 AM (UTC) |
| Message
|
Quote:
When a subroutine is called from an alias, or from a trigger, the alias/trigger attempts to pass three arguments to the subroutine:
SourceCallingName - The label of the alias or trigger making the call.
TheOutput - From a trigger, the whole line which caused the trigger to fire, from alias, I assume 'Empty'.
TheWildcards - an array of all the wildcards.
For an alias "theoutput" is the output generated by the alias. For example, if you have an alias:
Alias: eat
Send: eat pie
The words "eat pie" will be passed down as "theoutput".
Quote:
A timer tries to pass along just one argument. It's a Error/Status code, that indicates either success, or a code
representing an error. (Read the help for that function to learn more).
The timer expects one argument, which is the timer name. I think you are thinking of "addtimer" which returns an error code.
Thus a timer could be defined like this:
sub mytimer (strName)
world.note "timer called had name of " & strName
end sub
This lets you share timer scripts between different timers.
Quote:
There's more to be learned about arrWildcards above, such as what arrWildcards(0) holds...
There is no wildcard 0 (using it gives "array out of bounds") however there is a wildcard 10, which is "the whole matching expression". I just noticed when doing this reply that MUSHclient has a bug, this only applies to triggers right now, not aliases.
There is a distinction between wildcard 10 and the "matching trigger line", which is this ...
For a normal (not regular expression) trigger, nothing, they are the same.
For a regular expression, which can match on a partial line, wildcard 10 is what the regular expression matches on, whereas the "matching line" is the entire line. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #10 on Tue 09 Apr 2002 12:16 AM (UTC) |
| Message
| Amplifying on my reply above, wildcard 10 (in a script) is wildcard %0 in the trigger itself.
For instance, if you wanted to make a trigger that logged the entire matching line, you might use this:
Send: %0
Send to: log file
In this case %0 is "the matching expression". However in a script, you refer to "arywildcards (10)" not "arywildcards (0)". |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Magnum
Canada (580 posts) Bio
|
| Date
| Reply #11 on Wed 10 Apr 2002 07:30 PM (UTC) |
| Message
| | Man, did I ever goof on my reply... LOL. Thank God for Nick. :) |
Get my plugins here: http://www.magnumsworld.com/muds/
Constantly proving I don't know what I am doing...
Magnum. | | 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.
33,485 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top