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
➜ Reading prompt
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Aerath
(8 posts) Bio
|
Date
| Mon 22 Aug 2005 04:12 PM (UTC) |
Message
| I know this is a question that might be dealt with many times but i have the following problem.
I want to read my prompt, its like this: 3842h, 2955m ex-
I dont know much of VBscript and Plugins and the such so help me out here please.
I want to read health, mana, e (=equilibrium) and x (=balance) and store em into variables Health, Mana, Equilibrium and Balance.
Health and Mana will be some higher number and Eq and Bal will be 1 or 0 whether this is true or not.
I just dont know how to read that stuff from the prompt i dont know either how to use the plugin's to make reading from prompt without have old promt what is discussed in another post.
Could someone loan me some help here, appreciated! | Top |
|
Posted by
| Tsunami
USA (204 posts) Bio
|
Date
| Reply #1 on Mon 22 Aug 2005 05:45 PM (UTC) |
Message
| I use VBScript to code all that. First you have the prompt trigger of course, which for me, looks something like this:
^(\d+?)h, (\d+?)m (.+)-$
So then lets say this trigger calls a function, 'prompt':
sub prompt(name,output,wildcs)
...
end sub
then wildcs(3) contains a string such as 'ex', or 'x', or 'ec', or whatever the case may be. Then I use the InStr function to pull out balance, eq etc... So:
(I may have gotten the argument order to InStr wrong here, I did it off the top of my head)
if(InStr('x',wildcs(3)) then
balance = vbTrue
end if
if(InStr('e',wildcs(3)) then
eq = vbTrue
end if
etc...
Get the idea? | Top |
|
Posted by
| Larkin
(278 posts) Bio
|
Date
| Reply #2 on Mon 22 Aug 2005 09:38 PM (UTC) |
Message
| I would recommend a few alterations to your regular expression, to ensure that you catch all prompts (such as ones with no prompt flags) properly.
^(\d+)h\, (\d+)m.*? ([cexkdb@]*)-$
This pattern also works when you configure your prompt with endurance or willpower, though it doesn't capture them. | Top |
|
Posted by
| Aerath
(8 posts) Bio
|
Date
| Reply #3 on Mon 22 Aug 2005 10:46 PM (UTC) |
Message
| Hmm is getting really clear now but i still have some problems with the InStr() function which doesnt seem to work with me..
I tried just the same example as Tsunami said.. | Top |
|
Posted by
| Flannel
USA (1,230 posts) Bio
|
Date
| Reply #4 on Tue 23 Aug 2005 12:23 AM (UTC) Amended on Tue 23 Aug 2005 12:24 AM (UTC) by Flannel
|
Message
| Your InStr arguments are incorrect, swap them (large string, then small string to find within large).
Technically, you can (provided you're just using things like if later, like if balance, and not if balance = VBTrue, which is redudant. (Or would it be if balance Is VBTrue? Anyway.)
You can just do something like this:
balance = InStr(wildcs(3),"x")
Notice the double quotes (single quotes are comments, Im surprised you havent gotten weird errors about that too).
If you DO need to have it be strictly True/False, then you can do this:
balance = (InStr(wildcs(3),"x") <> VBFalse)
I suggest doing the != false, because VBTrue has a numeric value of -1, and the <> will force it to think that that is a comparison, since... well, I dont even want to know what the VBInterpreter might try to do otherwise. Probably nothing. But you definately dont want to deal with True being treated as -1 (any other non-zero evaluates to true though, which is why if youre using balance/etc in purely IF ways, youll be ok. |
~Flannel
Messiah of Rose
Eternity's Trials.
Clones are people two. | Top |
|
Posted by
| Aerath
(8 posts) Bio
|
Date
| Reply #5 on Wed 24 Aug 2005 09:50 PM (UTC) |
Message
| Allright, it all works fine now, i can read and store the parts of my prompt, health, mana, balance, equilibrium etc. and use em properly :)
My thanks to you guys who made this clear to me.
But i still have the problem with the outdated values of certain variables such as the variable balance and equilibrium which hold a numer 1 or 0 for true/false.
I found another post pointing to this thread:
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=3774
It seems i have to use this plugin to make the values of the prompt i want to store right instead of outdated at the time.
Altough i don't know exactly how to use this plugin, i have a different prompt then used in the plugin and i also wonder what it does exactly, e.g. is the plugin basically a trigger which will be checked? and can i use this plugin with other triggers outside of the plugin?
I need to call a script named prompt, this has to check the prompt at THAT EXACT moment and then store numbers into the variables balance/equilibrium.
This had to be checked at anytime in the active world, so the variables are up to date every moment i want to use em..
I hope you all get the point of this, and i really have no clue how to fix this now heh.
If someone could help me out with this finishing touch i would be really grateful.
Thanks alot already! :) | Top |
|
Posted by
| Flannel
USA (1,230 posts) Bio
|
Date
| Reply #6 on Wed 24 Aug 2005 10:07 PM (UTC) |
Message
| The problem is that the prompt line does not get sent with a trailing newline (like all other lines do). And because of this, mushclient doesn't check the line (for triggers) until the end of the line (the newline), which only occurs after another line has happened.
Originally, the 'workaround' was to (if you could on your server) change your prompt to include a newline (and then the end of the prompt is the next line, with nothing on it, but your important data has already been triggered).
Then we got the OnPluginPartialLine callback, and we can use that to peek into the last line we have, and then see if it matches.
We now have a third option (well, its the first solution, but we can do it clientside). OnPluginPacketReceived can be used to actually append a newline to the prompt line, which means it gets triggered by normal triggers and stuff.
There are better explanations in this forum, the best way to find them are to search for the callbacks (as they are long and unique). There are pros and cons to using each of the methods, as well as means of getting around those cons. But yeah, search for OnPluginPacketReceived and (seperately) OnPluginPartialLine, and (almost) all of the results will have to do with this dilemma. |
~Flannel
Messiah of Rose
Eternity's Trials.
Clones are people two. | 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.
27,436 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top