How to Match 'Directions, south west northeast southeast' ?

Posted by Karl_Newbie on Sun 26 Sep 2004 08:39 AM — 5 posts, 21,177 views.

USA #0
How do I match with a trigger the exits on my mud?
I want to capture the exit so I can use it as a wild card in a trigger or a variable.

I always see a line like the ones below.


Directions, south west northeast southeast

Directions, north south down east west

Directions, north south up

Directions, south up north

Directions, southwest west northwest in up

Directions are always a compass direction never a room name.
They always have two spaces after them, even the last one.

One problem is the mud does not list the directions in the same order even in rooms with similar directions.
Another is they can even spread across two lines if there are many directions.



I think the trigger would have to start like:

^Directions, (.*?)$

:)

But how do I set it so that there is a wildcard for every possible exit? Some rooms have 1 and others can have up to 10.

I just want a random auto walk trigger that doesn't send invalid directions to the mud.
Sort of like
randomize
social = Int( (n= number of directions*rnd)
if social=0 then
World.Send "%1"
elseif social=1 then
World.Send "%2"
elseif social=2 then
World.Send "%3"
etc
end if

I think would work

or using variables tho that would be more complicated and pointless I'd imagine?


randomize
social = Int(3*rnd)
if social=0 then
World.Send "getvariable("direction1")
elseif social=1 then
World.Send "getvariable("direction2")
elseif social=2 then
World.Send "getvariable("direction3")"
etc
end if


It's the matching trigger I have trouble with.
Amended on Sun 26 Sep 2004 02:36 PM by Karl_Newbie
Australia Forum Administrator #1
It will be hard to make a trigger that matches a variable number of directions and make each one a wildcard, although it could be done.

What would be easy enough to simply use your trigger and then use "split" to break the text into multiple words.
USA #2
Aso, thanks. I tried something like this with the split.

Match - ^Directions, (.*?)$

send

Dim Exitstring, ExitArray

ExitString = "%1"

ExitArray = Split(ExitString, " ", -1, 1)

randomize
social = Int(4*rnd)
if social=0 then
DoAfter 2, ExitArray(0)
elseif social=1 then
DoAfter 4, ExitArray(1)
elseif social=2 then
DoAfter 1, ExitArray(2)
elseif social=3 then
DoAfter 3, ExitArray(3)
[etc)
end if

But no I can't figure out what I'm doing wrong here. In rooms without enough directions for the randomize bit I get the 'nostring number' error.
And it still seems to only send the first exit.
Can you please help me along?


Amended on Wed 29 Sep 2004 01:49 AM by Karl_Newbie
Australia Forum Administrator #3
Your problem is that the rnd*4 is returning a number assuming 4 exits. Try this, it is simpler:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="^Directions, (.*?)$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>ExitArray = Split ("%1", " ")
DoAfter 2, ExitArray (Rnd * UBound (ExitArray))

</send>
  </trigger>
</triggers>



Using UBound, it finds the actual number of matching exits, and generates an appropriate random number.
Greece #4
Actually that's ExitArray(Int(Rnd*(Ubound(ExitArray) + 1))) as the manual suggest, otherwise it will give decimal numbers in the range 0-3.