[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Convert_word plugin

Convert_word plugin

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


Posted by Khonsu   (5 posts)  [Biography] bio
Date Wed 28 Jul 2021 06:04 PM (UTC)
Message
Hello. I've been trying to get an old plugin I found here to work with "special" characters. In the MUD I play there's an area that has a type of hieroglyph that you have to learn to translate. Instead of using a key to manually translate each and every time I was hoping to have a script convert it.

I've been trying to use the Lua script found here:
http://www.gammon.com.au/forum/?id=8747&reply=4#reply4


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Convert_Word"
   author="Nick Gammon"
   id="9c0ed228bdb4a71c77e85ce0"
   language="Lua"
   purpose="Converts one word to another"
   date_written="2008-06-29"
   requires="4.00"
   version="1.0"
   >

</plugin>

<!--  Script  -->

<script>

conversions = {
  foo = "bar",
  dog = "cat",
  horse = "donkey",

  -- add more here
  }
  
function OnPluginPacketReceived (s)
  return (string.gsub (s, "%a+", conversions))
end -- function OnPluginPacketReceived
</script>

</muclient>


I would want \:\ to convert to the letter S, for example.

However the characters I want it to match are "symbols" like \:\ and -:-, etc. Every time I try to match these I get different types of errors when putting \:\ in quotes or double brackets [[]]. I don't know enough to escape the special characters or whatever needs to be done. Trying to put an extra \ before each symbol will throw another error as well.

An example error would be : [string "Plugin: Convert_Word"]:3: '}' expected (to close '{' at line 1) near '='

Any help with this would be greatly appreciated.
[Go to top] top

Posted by Nick Gammon   Australia  (22,928 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 28 Jul 2021 10:40 PM (UTC)

Amended on Wed 28 Jul 2021 10:41 PM (UTC) by Nick Gammon

Message
First, the "key" (left side) has to be in brackets if it isn't a "word". And if it is a string it has to also be in quotes, for example:


conversions = {
  ["/:/"] = "a",
  ["-:-"] = "b",
  ["$:$"] = "c",

  -- add more here
  }


Second, your regular expression (the string.gsub) won't match because "%a" only matches letters. So you need a way of matching these hieroglyphs. For example, do they always have a colon in the middle? In which case you might match on ".:." instead of "%a+" (this is because a dot matches anything).

Third, I wouldn't do this in OnPluginPacketReceived because things that look like your hieroglyphs might show up elsewhere. It would probably be better to make an alias, and then copy the hieroglyph to the clipboard, and then get the alias to do the translation, when you want it to. eg.


translate /:/ -:- $:$

Alias responds:

a b c

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Khonsu   (5 posts)  [Biography] bio
Date Reply #2 on Thu 29 Jul 2021 12:02 AM (UTC)
Message
Thank you! This has helped me with figuring out how I can match these. I guess it was more of a problem with %a and the script was not getting alpha characters.. or something, pretty inexperienced here. Gonna try to look that up. Unluckily not all the hieroglyphs have a colon in the middle or are three characters, although they are either 2 or 3 and is an alphabet cipher so there's not too many different ones.

I believe I could write multiple functions to translate different ones perhaps. Going to fiddle with it more but I've at least got something working now.
[Go to top] top

Posted by Nick Gammon   Australia  (22,928 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 30 Jul 2021 11:45 PM (UTC)
Message

Are they separated by spaces? That would help.

Otherwise I would do something like this:

  • In a loop, get the first two characters
  • Look them up to see if they match a 2-character glyph
  • If a match, output that, remove 2 characters from the start of the string, and repeat (until none left)

Otherwise

  • Get the first three characters
  • Look them up to see if they match a 3-character glyph
  • If a match, output that, remove 3 characters from the start of the string, and repeat (until none left)

If no match still? Maybe skip one character and try again.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


8,286 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]