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 ➜ Scripting and Trigger help.

Scripting and Trigger help.

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


Posted by Christof   (10 posts)  Bio
Date Wed 21 May 2003 10:52 PM (UTC)
Message
I play a mu* that when you die, you're transported to a maze. The object is to find a hermit, and he brings you back to life. My problem is twofold. I need to match the room exits on the compass. The compass is on three lines, like such:

 A Maze of Twisty Passages                              -      N      -
(-------------------------------------------------)     W <---(M)---> E
 WARNING: You are in a CHAOTIC PLAYER KILLING room.     -      S      -


All possible exits are North, South, East, West, Northeast, Northwest, Southeast, Southwest, and Down.

Now, my triggers match when the exits are there, by looking at N, S, etc. My first problem is that when there is an exit on the NE, NW, SE, and SW exits, the triggers aren't matching because the compass text is slightly different:


 A Maze of Twisty Passages                              -      -     NE
(-------------------------------------------------)     - <---(M)---> E
 WARNING: You are in a CHAOTIC PLAYER KILLING room.     -      S     SE


I'm using trigs that would match if all the exits weren't there, as denoted by the "-"'s. NE, NW, SE, and SW arent being picked up.

Here are my trigs:

 A Maze of Twisty Passages                              *      *     *

etc..

Second problem, I've got the exits stored in boolean variables, but I'm not sure how to fashon a function to randomly move around.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #1 on Thu 22 May 2003 08:18 PM (UTC)
Message
Hmm. First off. You are better off using regular expressions for this:

^ A Maze of Twisty Passages\s{30}(-|NW)\s{5,6}(-|N)\s(5,6)(-|NE)$

and

^ WARNING: You are in a CHAOTIC PLAYER KILLING room.\s{5}(-|SW)\s{5,6}(-|S)\s{5,6}(-|SE)$

An explaination:

^ and $ - I often call these spoof proofers. Why? Because ^ makes certain that the line starts with that character, you don't have to worry about some moron doing:

[OOC] Fred: I'm seeing A Maze of Twisty Passages - N -

and have it confuse your trigger. Same with $, which specifies that the 'end' of the line must be at a specific location, though in this case you could probably leave it off.

\s in a regular expression specifies a space. It is followed by *, +, ? or {min,max}.

The first two types are equivalent to {1,}, the ? is {0,1}. ;)

In the first trigger for example we use {30} to tell it to look for 30 spaces. You could make it {30,} to mean at least 30 or {,30} would mean anything less than 31. Since know (or assume) it will always be 30, we only give it that number, which means both 'min' and 'max' are 30. Then later we use \s{5,6}. This allows the number of spaces to shrink from the normal 6 to 5 whenever NW is found. We do the same for the last exit. With the second of the three triggers you are using, this is not needed, since there is no big spaces or changes in size that happen if the exit is there or not, but we do use the same tactic on the last trigger.

Now as for the wildcards. In regular expressions you need to place () around anything you want to pass as a wildcard. In this case we are testing for - or a direction. That is what | does in there. ;) Note that in some cases this is a problem, since () is required when using | to check multiple possibilities, but if you only want to test for them, but not pass them on, you are out of luck. In this case you are lucky, since you are not just testing for something, but actually using the result.

Here is an example of when it is annoying:

Match = "^[(newbie|gossip|sales)]: .*"
SendTo = "Notepad"

In this case you don't care what chat channel is being sent to the notepad, you are sending all three there anyway, but the channel name is passed as the first wildcard. In a complex trigger this can get quite annoying, since you may be testing 6-7 different things that may use more than one possible word, but only want to actually use the 3rd and 5th items. Definitely something to be careful of since if you use the wrong wildcard from such a mess you might spend a lot of time trying to figure out what isn't working with your script, only to realize you are using the wrong values... I've done it a few times. lol


Now for movement.. This is a more complex issue. You will probably need to trigger on whatever you mud uses as a prompt. This is so you can test for the hermit being in the room 'before' the client has the chance to use the room exits to move at random. My suggestion is to have the hermit being found disable the prompt trigger, you can then use your death message to enable this trigger. This will make sure that the random move stuff only happens when dead and ends when you want it to. ;)

Now for the script:

I assume you already have the stuff to set your binary bits and that you 'mean' stored in one variable, not several -
sub RandMove (tname, output, wilds)
  a = 0
  do
    'Gives a binary number from 2^0 to 2^7.
    'This 'should' be the same range as your binary. ;)
    b = 2^int(rnd * 8)

    'This is where you store your directions. Call it what
    'ever you are already using instead. If using a global
    'script variable, then skip this and use that instead
    'of c in the following code.
    c = getvariable("ValidDirs")

    for d = 7 to 0 step -1
      e = 2^d 'Get the next biggest binary value.
      if c >= e then 'Test to see if it is even a 'possible' direction.
        if b = e then 'See if the random direction is also the valid on we found.
          a = -1 'If yes, then exit this mess.
          exit for
        end if
        c = c - e
      end if
  until a = -1

  'Use whatever the last direction tested was to determine how to move.
  'You should rearrange the following to match the way you set up your booleans.
  'Also, if 0, 1, 2, etc. does not work then try using "0", "1", "2", etc. ;)
  select case d
    case 0
      send "northwest"
    case 1
      send "north"
    case 2
      send "northeast"
    case 3
      send "east"
    case 4
      send "southeast"
    case 5
      send "south"
    case 6
      send "southwest"
    case 7
      send "west"
  end select
  setvariable "ValidDirs", 0 'Clear directions, since we moved and they are now invalid.
end sub


Note.. If you are using an array or multiple boolean variable, then this is a bit different, but you can use stuff like this instead to build the type I used:
Match = <Your first line here>
RegEx = "y"
SendTo "Script"
Send = "
  if %1 = "NW" then
    setvariable "ValidDirs", getvariable("ValidDirs") + 1
  end if
  if %2 = "N" then
    setvariable "ValidDirs", getvariable("ValidDirs") + 2
  end if
  if %3 = "NE" then
    setvariable "ValidDirs", getvariable("ValidDirs") + 4
  end if

Match = <Your second line here>
RegEx = "y"
SendTo "Script"
Send = "
  if %1 = "W" then
    setvariable "ValidDirs", getvariable("ValidDirs") + 128
  end if
  if %2 = "E" then
    setvariable "ValidDirs", getvariable("ValidDirs") + 8
  end if

Match = <Your last line here>
RegEx = "y"
SendTo "Script"
Send = "
  if %1 = "SE" then
    setvariable "ValidDirs", getvariable("ValidDirs") + 16
  end if
  if %2 = "S" then
    setvariable "ValidDirs", getvariable("ValidDirs") + 32
  end if
  if %3 = "SW" then
    setvariable "ValidDirs", getvariable("ValidDirs") + 64
  end if
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #2 on Fri 23 May 2003 04:27 PM (UTC)
Message
Isn't there an "Exits: " line?

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Christof   (10 posts)  Bio
Date Reply #3 on Mon 26 May 2003 11:40 PM (UTC)
Message
Looks sound, but I keep getting the following error:


Error number: -2146827264
Event: Execution of line 199 column 3
Description: Expected statement
Line in error:
until a = -1
Called by: Immediate execution


And no, the compass serves as the 'exits' line.
Top

Posted by Christof   (10 posts)  Bio
Date Reply #4 on Tue 27 May 2003 01:34 AM (UTC)
Message
Well... the hermit would be found in a down. So, that adds another direction to this. The do/for statements were broke until I added a next/loop statement. There was a problem with the if/then statements in the triggers, they faulted (and crashed the program) on the "-"'s, so I changed the logic to:
[code]
If "%n" <> "-" then
[/code]

And that seems to pass the correct variables along.I'm not sure how to make the middle a regular statement, but it stays pretty much the same:

[code]
(-------------------------------------------------) W <---(M)---> E
[/code]

except when the hermit is found, then its:

[code]
(-------------------------------------------------) W <---(M)-D-> E
[/code]

So, I made a trigger like this:

[code]
Match = (-------------------------------------------------) * <---(M)-*-> *

RegEx = "y"
SendTo "Script"
Send = "
if "%1" <> "-" then 'West
setvariable "ValidDirs", getvariable("ValidDirs") + 128
end if
if "%2" <> "-" then 'Down
setvariable "ValidDirs", getvariable("ValidDirs") + 8
end if
if "%3" <> "-" then 'East
setvariable "ValidDirs", getvariable("ValidDirs"0 + 256
[/code]

And it all seems to do ok, except it spams "west", twice.

*boggle*





Top

Posted by Christof   (10 posts)  Bio
Date Reply #5 on Tue 27 May 2003 02:11 AM (UTC)
Message
I guess the whole do/loop thing isn't working, it spams the last 'case' item. Found that out by changing the final case selection.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #6 on Tue 27 May 2003 06:57 AM (UTC)
Message
Just ran some tests. I got the last repeating like you said when intentionally recalling the sub, this was due to the routine using 0 as a reset value and not specifically exiting if it was. It would thus always return a direction even if the sub was called 'after' it shouldn't be. Basically somehow it was getting called twice in a row and that caused it to pick a random from the valid choices the first time, but then the second time it bailed out with d = 7 and sent the last direction in the case list. I also made some simple but stupid mistakes that where responsible for the other issues you had. The following is the corrected version (changed lines are commented with ***):

sub RandMove ()
  a = 0
  do
    'Gives a binary number from 2^0 to 2^7.
    'This 'should' be the same range as your binary. ;)
    b = 2^int(rnd * 8)

    'This is where you store your directions. Call it what
    'ever you are already using instead. If using a global
    'script variable, then skip this and use that instead
    'of c in the following code.
    c = getvariable("ValidDirs")

    if c = "-1" then '*** Test to see if we re-entered after a reset and exit if yes.
      exit sub
    end if

    for d = 8 to 0 step -1
      e = 2^d 'Get the next biggest binary value.
      if c >= e then 'Test to see if it is even a 'possible' direction.
        if b = e then 'See if the random direction is also the valid on we found.
          a = -1 'If yes, then exit this mess.
          exit for
        end if
        c = c - e
      end if
    next '***Kind of important
  loop until a = -1 '*** Forgot the 'loop' part, which caused the error.

  'Use whatever the last direction tested was to determine how to move.
  'You should rearrange the following to match the way you set up your booleans.
  'Also, if 0, 1, 2, etc. does not work then try using "0", "1", "2", etc. ;)
  select case d
    case 0
      send "northwest"
    case 1
      send "north"
    case 2
      send "northeast"
    case 3
      send "down" '*** To support your change.
    case 4
      send "southeast"
    case 5
      send "south"
    case 6
      send "southwest"
    case 7
      send "west"
    case 8
      send "east" '*** To support your change. Making 'Down' be this would have made more sense to me, but..
    case else '*** Not needed, but nice to add anyway, just in case a later change screws things up.
      colournote "red","black","Error! Random direction invalid!"
  end select
  '*** We now use -1 here to make it more obvious that we have cleared the variable.
  '*** 0 would have still worked if tested for, but since I didn't expect an extra call to this sub, I hadn't bothered.
  setvariable "ValidDirs", -1 '*** Clear directions, since we moved and they are now invalid.
end sub


Things to remember when I post code. ;) I probably haven't specifically tested it unless I actually say I did, I sometimes leave out minor but important things and it was usually typed in about five minutes while actually thinking about how to solve the problem. This is a good thing since I can code stuff like this off the top of my head, but also bad since it usually has bugs I don't notice because I go off to do other stuff right after posting it. lol

Then again, no one else noticed the glaring lack of a 'next' or 'loop' command in there either. ;) lol
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.


21,816 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.