Using somthing to display information below a trigger?

Posted by Dphyre on Tue 10 Jan 2023 09:42 AM — 4 posts, 12,452 views.

#0
So I'm trying to drive a boat, but the directions are confusing me. I'll try and explain. At the start of the voyage, the ship is facing completely hubwards. Thus, when looking at the ocean at the start you would position yourself like this:

------ ---------------hubwards
-turnwise-hubwards ^ widdershins-hubwards
-----------------------\ | /
---------turnwise <- ship -> widdershins
-----------------------/ | \
-turnwise-rimwards v widdershins-rimwards
-----------------------rimwards

You're always trying to go Hubwards, toward City A. A skilled sailor can look at the sun if its daylight, or the stars if its nighttime, and if they pass the check, the'll get a message similar to these:

"Squinting up at the sun, you determine that the ship is heading hubwards and that you're three hundred and eighty-seven miles rimwards and nine miles widdershins of City A."

"Squinting up at the sun, you determine that the ship is heading widdershins-hubwards and that you're two hundred and ninety-one miles rimwards and fifty-seven miles widdershins of City A."

"Squinting up at the sun, you determine that the ship is heading widdershins-rimwards and that you're two hundred and forty-nine miles rimwards and sixty-three miles widdershins of City A."

So with those messages in mind, and knowing that you're always trying to go toward city A, it can get confusing. If the ship is already going straight Hubwards, well that's great, but sometimes its not. If a sailor gets turned around or in a whirlpool, it can be going any direction.

I understand that I can use regular expression to capture the directions, I think, and even the numbers (not as important to me) when I trigger that message and use the ColourNote function to print out below the message I triggered to tell me the actual way to go.

So for the first trigger, ideally it would print below it: '87 miles Hubwards to City A, Adjust heading turn-hub for 9 miles'

For the second trigger it would ideally print below it: "291 miles away from city A, adjust heading turn-hub for 57 miles"

For the third trigger it would ideally print below it: "249 miles away from city A, adjust heading turn-hub for 63 miles"

Now I realize since I got confused typing that up, it might not make since. I'd

^((Squinting up at the sun|Gazeing up at the stars), you determine that the ship is heading (?<direction>.*?)( and that you're (?<miles_y>.*?) miles? (?<rim_or_hub>rimwards|hubwards)( and (?<miles_x>.*?) miles? (?<turn_or_wid>turnwise|widdershins))? of .*?)?\.$

I was hoping I could use something like that to capture the miles, and the directions, store them in a variable maybe, and have it transpose the directions for me. I'm not looking for anything that inputs commands to the mud itself, obviously, but something that inserted information next the triggered line itself would be helpful.

so anytime the mud seen "widdershins-rimwards" it would spit out (TH) or anytime the mud seen"turnwise-rimwards" it would spit out (WH) in bright colors to make it easier to see.

If anyone could provide any help or guidance, I would be much appreciated.


Thank you.
Amended on Tue 10 Jan 2023 09:46 AM by Dphyre
USA Global Moderator #1

First lets get your trigger pattern to work…

^((Squinting up at the sun|Gazeing up at the stars), you determine that the ship is heading (?<direction>.*?)( and that you're (?<miles_y>.*?) miles? (?<rim_or_hub>rimwards|hubwards)( and (?<miles_x>.*?) miles? (?<turn_or_wid>turnwise|widdershins))? of .*?)?\.$

Looks slightly wrong to me. I think you’ll want ?P to start your named captures, not just ?.

Also make your trigger send to Script, since you’ll need to do some script functions to convert some words to numbers (“fifty-seven” to 57).

Once your trigger matches on your line, you should be able to access the named captures with “%” in your code.

The hardest part of this is going to be converting the words to numbers, but MUSHclient does already have some code that will almost do exactly what you need for that, but it expects slightly different formatting (no dashes), so I think first you’ll want to replace “-” with ” ” in the “%” variable.

Maybe try something like…

miles_x = string.gsub("%<miles_x>", "-", " ")

require "words_to_numbers"
miles_x_number = convert_words_to_numbers(miles_x)

ColourNote("white", "green", miles_x_number)

so anytime the mud seen “widdershins-rimwards” it would spit out (TH) or anytime the mud seen”turnwise-rimwards” it would spit out (WH) in bright colors to make it easier to see.

For this part it sounds like you’ll want either a series of conditions “if it’s this then do that, else if it’s this then do that, else …” or a lookup table. Maybe something like

direction_lookup = {
   ["widdershins-rimwards"] = "TH",
   ["turnwise-rimwards"] = "WH",
}

ColourNote("white", "green", direction_lookup["%<direction>"])
Amended on Wed 11 Jan 2023 09:19 AM by Fiendish
Australia Forum Administrator #2
@Fiendish - in markdown quotes are a line starting with ">" not [quote] ... [/quote].
USA Global Moderator #3
Nick Gammon said:

@Fiendish - in markdown quotes are a line starting with ">" not [quote] ... [/quote].

Heh. I didn't realize I couldn't mix!