Register forum user name Search FAQ

Gammon Forum

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 ➜ Checking one variable against a list

Checking one variable against a list

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by ErockMahan   (81 posts)  Bio
Date Fri 16 Jul 2010 10:45 PM (UTC)
Message
I have a list of people I want to perform a seperate action against. I store the list in @omit and seperate each name by a space (but I can change that if it helps). When it comes time to run the alias (something simple like 'reward *') it does the following:

bit = "@omit"
omit = Split(bit, " ")

For u = 0 to Ubound(omit)
if "%1"=(omit(u)) then
world.send "tell %1 you get NOTHING!"
else
world.send "tell %1 you get IT ALL!"
end if
Next


It looks like it should work, but it is checking against EVERY instance of the string instead of finding it once and moving on. I'd rather it checked once and then stopped...
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #1 on Fri 16 Jul 2010 10:54 PM (UTC)

Amended on Fri 16 Jul 2010 10:55 PM (UTC) by Twisol

Message
I'm not terribly familiar with VBscript, but you should be able to use Exit For from within the loop.

bit = "@omit"
omit = Split(bit, " ")

  For u = 0 to Ubound(omit)
    if "%1"=(omit(u)) then
      world.send "tell %1 you get NOTHING!"
      Exit For ' put this where you want to break out of the loop
    else
      world.send "tell %1 you get IT ALL!"
    end if
  Next


However I question whether you really mean what this code is doing. You're going over the list, and for each one, you send "...IT ALL!" or "...NOTHING!" depending on if there's a match. What I think you meant is this:

bit = "@omit"
omit = Split(bit, " ")
found = False

  For u = 0 to Ubound(omit)
    if "%1"=(omit(u)) then
      world.send "tell %1 you get NOTHING!"
      found = True
      Exit For
    end if
  Next

If found = False Then
  world.send "tell %1 you get IT ALL!"
End If


I don't know how much this could be condensed or clarified. Still, I think it would work.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by ErockMahan   (81 posts)  Bio
Date Reply #2 on Thu 22 Jul 2010 02:39 PM (UTC)
Message
You nailed it. Thanks a ton!
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.


13,104 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.