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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Lets start the conversion.

Lets start the conversion.

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


Pages: 1  2  3 4  5  

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #30 on Mon 13 Dec 2004 05:30 AM (UTC)
Message
No, it won't work in "send to script".

For one thing, notes done in "send to script" are not displayed, if the line is omitted from output.

For another thing, there is no fourth argument in "send to script". It isn't called as a function with arguments.

If you want to do it that way, it has to go into the script file. As Flannel says, the alternative is to use the preprocessing at the packet level.

- Nick Gammon

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

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Reply #31 on Mon 13 Dec 2004 05:46 AM (UTC)

Amended on Mon 13 Dec 2004 09:06 AM (UTC) by David Berthiaume

Message
Next small issue in your help file...

I checked out that AppendToNotepad... Works, but not quite the way the helpfile shows.
Quote:
AppendToNotepad("Nick's window", "More stuff\r\n",
                "another line")


Now, the \r\n is to make a new line? Doesn't seem to work properly, I keep getting errors.
Quote:
Still, changing to ColourTell should do it, followed by a final ColourNote to finish off the line.
Not sure where you gotta put the final ColourNote in there, it's seeming to be working just fine with only ColourNote.
Quote:
If you want to do it that way, it has to go into the script file. As Flannel says, the alternative is to use the preprocessing at the packet level.

reprocessing on the packet level would work, but I don't want to mess with the ANSI coding on it, I like the colours as it is for now. Perhaps in the future.

Quote:
No, it won't work in "send to script".

For one thing, notes done in "send to script" are not displayed, if the line is omitted from output.

For another thing, there is no fourth argument in "send to script". It isn't called as a function with arguments.

If you want to do it that way, it has to go into the script file. As Flannel says, the alternative is to use the preprocessing at the packet level.
That isn't a problem for me, the question is of course, how do we modify a table/metatable from an alias?
Quote:
Everything below this quote is an off shoot of our discussion about replacing text.
First. Alias to add word replacements into a script file.

Alias match on: set replace text "*" "*"
That's all I got so far(Upon editing, re-editing, and editing the edits... I note that this isn't accurate any longer, but the alias is still important.)

I think a merger of two idea's here will work well. Can you use a table to define the replace text? Hack code job to follow the real code:
function ToTextReplace (name, line, wildcards, styles)

  for _, v in pairs (styles) do
    
    ColourTell (RGBColourToName (v.textcolour), 
                RGBColourToName (v.backcolour), 
                (string.gsub (v.text, "Altair", "Dummy")))  
  end

end

here's the pseudo table:
text = {}

text.list = {
  1 = 'Altair',
  2 = 'Ceriloch',
  3 = 'Ragnar'
  }
text.replacelist = {
  1 = 'Moe',
  2 = 'Larry',
  3 = 'Curly'
  }

Ok, time for a buncha pseudo-code of my own creation, of course it'll be wrong, but you'll get the idea

function textreplace (name, line, wildcards, styles)

Ok, first compare the wildcard to the text.list table, does any of them match the criteria? 

Yes, Ok, then set it as text.match(see below)
       text.match = text.list.1

Compare the text.list table, to the text.replace table.
Match them up accordingly, and set text.replacetext to the corresponding text.list match.

text.replacetext = text.replace.1

Continue with rest of the code, but with the modification as follows

  for _, v in pairs (styles) do
    
    ColourTell (RGBColourToName (v.textcolour), 
                RGBColourToName (v.backcolour), 
                (string.gsub (v.text, text.match, text.replacetext)))  
  end

else -- Pseudo code is basically an if statement. 

end -- if statement
end -- function


I'm certain there is an easier way, I'm can't seem to think of it at the moment, but this seems pretty straight foreward.

Make a table with the matches, make that table with the replace text, when a trigger, which is setup by the alias, goes off, it runs the script, which checks the lists(gonna find out who's naughty or nice), converts into text.match and text.replacetext, and substitutes it. Hell, I got most of the idea down, the problem is coding it, which I'm not sure about.

Alias sets up trigger to match on the match word.
Alias adds to tables text.list and text.replace

Trigger goes off, runs through script.
Script checks its text.list table, converts to text.match(for the match)
Script checks its text.replace table, converts the corresponding replace text to text.replacetext

Script runs through the gambit, and bam, you have a fully customizable auto-word replacement script.

A second alias, would remove the Trigger, and the appropriate information within the tables.

Alias match on: remove replace text "*"
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Reply #32 on Mon 13 Dec 2004 09:04 AM (UTC)
Message
Ok, considering I think we'll be talking about tables, and serialize quite a bit, I think we should move over to this thread:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=5022
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #33 on Mon 13 Dec 2004 04:41 PM (UTC)
Message
You want to switch his name with 'dummy'. You CAN do that with the packet callback thing. You dont have to change/mess with the colors either. You can just subsitute text for text.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #34 on Mon 13 Dec 2004 07:32 PM (UTC)
Message
Quote:

I checked out that AppendToNotepad... Works, but not quite the way the helpfile shows ...


That works for me. What was the error? In Lua (not other languages) you can have multiple arguments after the notepad name, and they all appear in the notepad. And yes, \r\n is a carriage-return linefeed.

Quote:

Not sure where you gotta put the final ColourNote in there, it's seeming to be working just fine with only ColourNote.


I thought you were getting a line per style. The ColourTell stays on the same line. A final ColourNote (after the loop) would start a new line.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #35 on Mon 13 Dec 2004 07:53 PM (UTC)
Message
Quote:

here's the pseudo table:

text = {}

text.list = {
1 = 'Altair',
2 = 'Ceriloch',
3 = 'Ragnar'
}
text.replacelist = {
1 = 'Moe',
2 = 'Larry',
3 = 'Curly'
}


I suggest you read the Lua manual about tables:


http://www.lua.org/pil/2.5.html


Tables can be basically two things (or both), a list of things keyed by number, as you illustrate above, or an associative array. Here is an example of doing a list:


t = {
  'Altair',
  'Ceriloch',
  'Ragnar'
  }

table.foreach (t, print)

-- Output:

1 Altair
2 Ceriloch
3 Ragnar


In this case Lua automatically assigns incrementing keys to each item, effectively making a vector. Now you can get at invidivual items:


print (t [2]) --> Ceriloch


However for a word-replacement thing you really want an associative array:


t =  {
  ['Altair'] = 'Moe',
  ['Ceriloch'] = 'Larry',
  ['Ragnar'] = 'Curly'
  }

table.foreach (t, print)

-- Output:

Ceriloch Larry
Ragnar Curly
Altair Moe


Now each item is keyed by its name, and the replacement can be found directly:


print (t ['Ragnar']) --> Curly


If the keys are straight names, you can save a bit of typing:


t =  
  {
  Altair = 'Moe',
  Ceriloch = 'Larry',
  Ragnar = 'Curly'
  }


Given our table of replacement words, we can rewrite the gsub nice and simply:


t =  
  {
  Altair =  'Moe',
  Ceriloch =  'Larry',
  Ragnar =  'Curly'
  }

line = "Altair went for a walk, he met Ceriloch but Ragnar surprised them"

repl = string.gsub (line, "(%a+)", function (w)
         if t [w] then
            return t [w]
         else
            return w
         end -- if
       end) -- function

print (repl)

-- Output:

Moe went for a walk, he met Larry but Curly surprised them



What this is doing is searching for a word (%a+) and if found looking it up in the associative array. If found, it uses the replacement, if not, it returns the original word.

- Nick Gammon

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

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Reply #36 on Mon 13 Dec 2004 08:21 PM (UTC)
Message
Quote:
That works for me. What was the error? In Lua (not other languages) you can have multiple arguments after the notepad name, and they all appear in the notepad. And yes, \r\n is a carriage-return linefeed.

<triggers>
<trigger
enabled="y"
match="* oocs '*'"
send_to="12"
sequence="100"
>
<send>AppendToNotepad("Nick's window", "More stuff\r\n",
"another line")</send>
</trigger>
</triggers>

Error number: 0
Event: Compile error
Description: [string "Trigger: "]:1: unfinished string near `"More stuff
'
Called by: Immediate execution

I used the sample code in the helpfile, and I just put it in send to script. That was the error I got.

I didn't even bother to change it to what it's supposed to be, if the helpfile example didn't work for me, then I know the setup I was going to use wasn't going to work either.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Reply #37 on Mon 13 Dec 2004 08:31 PM (UTC)
Message
Regarding that associative array, I hear ya. I know exactly what you mean. When I was reading the manual late last night, I saw the difference.

The only problem with what you put up, and there's nothing wrong with it, but it's missing something.

if I make an alias to add a name into the array, which is piece of cake

Alias: add "*" "*"
send to script: t ['%1'] = '%2'

That will add a new name and replace text into the array, but it's in memory, it's not actually hardcoded, so when you quit out, you're going to lose that array.

So, how about OnWorldConnect you load the saved array
and OnWorldDisconnect you serialize the memory array, that'll save it as a variable... That'll work I think. Actually, I think that'll be less work than trying to code it as changing the scriptfile itself.... Yeah, I like that.
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #38 on Mon 13 Dec 2004 09:04 PM (UTC)
Message
OK, I see what is happening. That trigger is a bit of a trap. The example code works pasted into the command window, however in the "send to script" box it seems MUSHclient is preprocessing the \r\n before passing it to Lua (or any script language). Thus it effectively makes it:


AppendToNotepad("Nick's window", "More stuff
",
"another line")


This make Lua complain about the unterminated quote on the first line.

You can fix it by using another backslash:


<triggers>
  <trigger
   enabled="y"
   match="* oocs '*'"
   send_to="12"
   sequence="100"
  >
  <send>AppendToNotepad("Nick's window", "More stuff\\r\\n", "another line")</send>
  </trigger>
</triggers>


However my code as given in the example works in a script file.

- Nick Gammon

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

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Reply #39 on Mon 13 Dec 2004 09:04 PM (UTC)
Message
Was playing around with the replacetext script

function textreplace (name, line, wildcards, styles)

  for _, v in pairs (styles) do
    
    ColourTell (RGBColourToName (v.textcolour), 
                RGBColourToName (v.backcolour), 
                (string.gsub (v.text, "Altair", "Dummy")))  
  end

end
Was the original code... Now, I'm kinda confused, granted I haven't slept in over 24 hours, so that could be it... but I'm not making the connection how to go from:
t =  
  {
  Altair =  'Moe',
  Ceriloch =  'Larry',
  Ragnar =  'Curly'
  }

line = "Altair went for a walk, he met Ceriloch but Ragnar surprised them"

repl = string.gsub (line, "(%a+)", function (w)
         if t [w] then
            return t [w]
         else
            return w
         end -- if
       end) -- function

print (repl)

-- Output:

Moe went for a walk, he met Larry but Curly surprised them
To using both in conjunction...

I'm still kinda stumped on the trigger aspect. I really don't want 50 million single triggers. I was thinking of something along the lines of (fdhgh|arhh|ahathaeh|bob|fdahah|great) And when I add a new word, to be replaced, it adds into the trigger, but I don't remember how to do that... I know the code is in the forums, I've used it before, but it's a bit beyond my current ability in Lua.
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #40 on Mon 13 Dec 2004 09:05 PM (UTC)
Message
Quote:

That will add a new name and replace text into the array, but it's in memory, it's not actually hardcoded, so when you quit out, you're going to lose that array.

So, how about OnWorldConnect you load the saved array
and OnWorldDisconnect you serialize the memory array ...


Yes, exactly. See my posts in the Lua section for doing that.

- Nick Gammon

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

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Reply #41 on Mon 13 Dec 2004 09:10 PM (UTC)
Message
Acutally, I picked up on serializing rather quickly, it's a really neat function, not sure how function save works though.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #42 on Mon 13 Dec 2004 10:21 PM (UTC)
Message
The matching on multiple (and dynamic) things can be done with expand variables and a variable that contains a regexp for what you want to match on.

bob|joe becomes
bob|joe|billy when you add to it. So its a simple string concatenation. You can do 95% of it without using any form of scripting (just the inbuilt functions) you only need the lua code to add "|[name]" to the variable.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #43 on Mon 13 Dec 2004 10:25 PM (UTC)
Message
After writing that I saw a couple of shortcomings in the serialization idea. Namely, when do you actually serialize the variable?

See my addition to this thread:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4960

I have added a couple of new things to MUSHclient 3.60. The first one lets you do a script just before MUSHclient saves its world to disk. This is a logical spot to serialize from internal variables to the external variables.

The second is a function that lets you set the "world has changed" flag, to make sure the saving is done in the first place.

I added this short script to my script file to make it work:


function OnWorldSave ()
  var.skills = serialize ('skills')
end -- function


That caused the skills to be serialized. Then in the world open:


function OnWorldOpen ()
  loadstring (var.skills) 
end


That loads them back in.


- Nick Gammon

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

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Reply #44 on Mon 13 Dec 2004 10:38 PM (UTC)
Message
I think this alias is going to be a lot more complex than we both think it's going to be.

Ok, really tired, I can't even think of how to do what Flannel said...

Mainly, I got the SetVariable ("replacetext", "@replacetext" .. "%1")

But that's all I got so far... and I know I have to put in the "|" in there, and I'm drawing a blank as to how to do that. I know I gotta script this into it as well:

text ['%1'] = '%2"

Then I'm drawing a blank.
[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.


128,207 views.

This is page 3, subject is 5 pages long:  [Previous page]  1  2  3 4  5  [Next page]

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]