Help with a Compass Plugin

Posted by Dabura on Mon 03 Nov 2003 03:45 AM — 11 posts, 35,330 views.

#0
Hello. This is my first attempt at using VBScript to do anything, and I need a bit of help figuring out what to do here.

Pretty much, i'm writing a script that triggers off of

Exits: * * * * * * * *

and then displays something a bit like this to the screen:

NW     N     NE
W <---(+)---> E
SW     S     SE

with the obvious alterations depending on the exits displayed.
What I was wanting to do was at first do a seperate output for each different combination of exits.. but with 8 different possibilities, that's not gonna happen. So, pretty much, I need help on figuring out how I should write all the ifs.
Amended on Mon 03 Nov 2003 04:18 AM by Dabura
USA #1
What exactly do you want your plugin to do? You say writing out things depending on the compass output, and that there are different possibilities depending on the exit combinations, but what exactly do you want your result to look like?
#2
For example.. if the exits are to the north, west, south, and east, then it would output

       N       
W <---(+)---> E
       S       

or if the exits were north, northeast and south it would be

       N     NE
  <---(+)--->  
       S       
Amended on Mon 03 Nov 2003 05:16 AM by Dabura
USA #3
One thing you can do is set up an array of 1s and 0s that indicate whether or not the exit is present or not. To find that out, you look at the string of exits, and see if "north" is in it. I think the function is InStr, or StrStr or something like that. I actually haven't used VB for quite a while, but InStr sounds familiar...

So once you have your array, you can display it accordingly. For instance, if northwest is "on", you add "NW" to your string, otherwise add " " to it (to keep the formatting correct.)

I can't think of a particularly clever way off the top of my head, but that seems like the simplest given the tools and constraints.
USA #4
There was a similar thread to this a while ago, except it was going the opposite direction. But you might be able to use some of the routines.

Do a search for compass, it should come up.
#5
Well.. i've gotten my script written up and my trigger made. But, it's not working. So, after I post this, i'm gonna go to bed and hope SOMEBODY helps me here.

<triggers>
  <trigger
   enabled="y"
   group="OnCompass"
   match="^Exits\: (.*?) (.*?) (.*?) (.*?) (.*?) (.*?) (.*?) (.*?) (.*?) .*?$"
   name="OnCompass"
   regexp="y"
   script="OnCompass"
   send_to="12"
   sequence="100"
   other_text_colour="black"
   other_back_colour="black"
  >
  </trigger>
</triggers>

There's my trigger.


sub OnCompass(name, output, wcards)
' North: 1
' East: 2
' West: 3
' South: 4
' Northeast: 5
' Northwest: 6
' Southeast: 7
' Southwest: 8
' Up: 9
' Down: 10
dim dirs(10)

' The following checks if any of the 10 directions are present in the 10 wildcards, and if so, assigns the respective
' direction to one of the members of the array "dir", and if not, assigns a blank space to the same member.
if wcards(1) or wcards(2) or wcards(3) or wcards(4) or wcards(5) or wcards(6) or wcards(7) or wcards(8) or wcards(9) or wcards(10) = "north" then
dirs(1) = "N"
else
dirs(1) = " "
end if

if wcards(1) or wcards(2) or wcards(3) or wcards(4) or wcards(5) or wcards(6) or wcards(7) or wcards(8) or wcards(9) or wcards(10) = "east" then
dirs(2) = "E"
else
dirs(2) = " "
end if

if wcards(1) or wcards(2) or wcards(3) or wcards(4) or wcards(5) or wcards(6) or wcards(7) or wcards(8) or wcards(9) or wcards(10) = "west" then
dirs(3) = "W"
else
dirs(3) = " "
end if

if wcards(1) or wcards(2) or wcards(3) or wcards(4) or wcards(5) or wcards(6) or wcards(7) or wcards(8) or wcards(9) or wcards(10) = "south" then
dirs(4) = "S"
else
dirs(4) = " "
end if

if wcards(1) or wcards(2) or wcards(3) or wcards(4) or wcards(5) or wcards(6) or wcards(7) or wcards(8) or wcards(9) or wcards(10) = "northeast" then
dirs(5) = "NE"
else
dirs(5) = " "
end if

if wcards(1) or wcards(2) or wcards(3) or wcards(4) or wcards(5) or wcards(6) or wcards(7) or wcards(8) or wcards(9) or wcards(10) = "northwest" then
dirs(6) = "NW"
else
dirs(6) = " "
end if

if wcards(1) or wcards(2) or wcards(3) or wcards(4) or wcards(5) or wcards(6) or wcards(7) or wcards(8) or wcards(9) or wcards(10) = "southeast" then
dirs(7) = "SE"
else
dirs(7) = " "
end if

if wcards(1) or wcards(2) or wcards(3) or wcards(4) or wcards(5) or wcards(6) or wcards(7) or wcards(8) or wcards(9) or wcards(10) = "southwest" then
dirs(8) = "SW"
else
dirs(8) = " "
end if

if wcards(1) or wcards(2) or wcards(3) or wcards(4) or wcards(5) or wcards(6) or wcards(7) or wcards(8) or wcards(9) or wcards(10) = "up" then
dirs(9) = "U"
else
dirs(9) = " "
end if

if wcards(1) or wcards(2) or wcards(3) or wcards(4) or wcards(5) or wcards(6) or wcards(7) or wcards(8) or wcards(9) or wcards(10) = "down" then
dirs(10) = "D"
else
dirs(10) = " "
end if

world.Note " _______________ "
world.Note "|(" & dirs(5) & ")--(" & dirs(1) & ")--(" & dirs(6) & ")|"
world.Note "|       |       |"
world.Note "|(" & dirs(3) & ")-([" & dirs(9) & "|" & dirs(10) & "])-(" & dirs(2) & ")|"
world.Note "|       |       |"
world.Note "|(" & dirs(8) & ")--(" & dirs(4) & ")--)" & dirs(7) & ")|"
world.Note "-----------------"

'  _______________ 
' |(NW)--(N)--(NE)|
' |       |       |
' |(W)-([U|D])-(E)|
' |       |       |
' |(SW)--(S)--(SE)|
' -----------------

end sub


There's obviously SOMETHING wrong with this, so please help me.
USA #6
Two things:
1- could you post the output?
2- you need to repeat the condition on every part of the if statement, e.g.
[code]
if wcards(1) = "north" or wcards(2) = "north" or wcards(3) = "north" or wcards(4) = "north" or wcards(5) = "north" or wcards(6) = "north" or wcards(7) = "north" or wcards(8) = "north" or wcards(9) = "north" or wcards(10) = "north" then
[/code]
There may be a nicer way of doing it. It would be cleaner to have a function that goes through the array searching for a string passed as an argument; then you could call like so:
[code]
if arrayContains(wcards, "north") then
[/code]
which is obviously much nicer.
Canada #7
Well. I'm kinda working with him on this. The exact trigger line is:

Exits: north east south west up down.

But there is also northeast and such so the trigger in regular expression should be (for the line above):

^Exits\: (.*?) (.*?) (.*?) (.*?) (.*?) (.*?)\.$

Correct?

Now. Although this isn't the method he was using, i figured it would be a little better. It's much like the chmod function for unix.

Assigning values to the directions in the trigger.

North: 1
East: 2
West: 4
South: 8
Northeast: 16
Northwest: 32
Southeast: 64
Southwest: 128
Up: 256
Down: 512

Ok. Here is where I have a problem. The trigger should be:

<triggers>
  <trigger
   enabled="y"
   group="OnCompass"
   match="^Exits\: (.*?) (.*?) (.*?) (.*?) (.*?) (.*?) (.*?) (.*?) (.*?) (.*?)\.$"
   name="OnCompass"
   regexp="y"
   script="OnCompass"
   send_to="12"
   sequence="100"
   other_text_colour="black"
   other_back_colour="black"
  >
  </trigger>
</triggers>


Correct?

I'm not sure how I could ensure that each direction gets it's appropriate number in the script. I was thinking

dirs(0) = 1
dirs(1) = 2
dirs(2) = 4


But that wouldn't work because the line can appear in many different ways.

Exits: north east south west up down.
Exits: east south.

Which means that dirs(0) won't always be 'north'.

That's why I think that the way Dabura's got it might be better, but as he said, we're not sure why it isn't working.

But, I just had a brainstorm so I'm going to try that out and see if it works.
USA #8
One reason it won't work is because of what I told you: you have to repeat the test in every sub-expression of the long if statement. Otherwise, you're having it interpret the string value to bool, and this means return true if the string is not empty.

The other thing I just noticed is that your regex is wrong. What if you have:

Exits: north.

Your trigger won't match, since it wants:
Exits: somethingSPACEsomethingSPACEsomething
if that makes sense to you. Your regex demands a list of space-separated entries, and you won't always get that amount.
USA #9
Why dont you use the For Each statement to cycle through?
For each direction have a for each loop, then if it finds it, it adds it to the number, or makes the string have a letter, or whatever.
#10
I had to do something similar to this, and I used the Split() function. I kept the whole string intact, so a regex trigger wasn't neccesary. Something that matches on "Exits: *" Example:

Exits: north east southwest

The first wildcard would contain all exits, like this: "north east southwest"

arrExits = Split(arrWildCards(1), " ", -1, 1)

Would return an array of each exit in text form.

Then something like this to walk through each one:

For Each r in arrExits
 '
 ' Process each exit individually
 ' 
 Select Case r
  Case "north" dirs(1) = "N"
  Case "south" 'etc
  Case "east"  
  Case "west"  
  'etc.
 End Select
Next


That would trim down the size of the script considerably, and should work better. I don't know how well the compass will draw on your screen. I think it might be best to preserve spaces in the empty ones, so the compass isn't drawn out all messed up.