|
Checking one variable against a list
|
Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
ErockMahan
(65 posts) bio
|
| Date |
Fri 16 Jul 2010 10:45 PM (UTC) [ quote
] |
| 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 (1,476 posts) bio
|
| Date |
Fri 16 Jul 2010 10:54 PM (UTC) [ quote
] 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
(65 posts) bio
|
| Date |
Thu 22 Jul 2010 02:39 PM (UTC) [ quote
] |
| 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.
359 views.
Reply to this subject
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )