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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

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

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Lets start the conversion.
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  3  4  5  

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Wed 15 Dec 2004 06:23 AM (UTC)  quote  ]
Message
Quote:
I am glad to hear it is working, but again I think you have combined a couple of my ideas into one.


Yep, I did, was the only way I could figure out how to get it to work.

I knew the first half of the code would change the line into the new words, and I knew the second half of the code would do the ColourTell.

I knew I could always match the apropriate capitolization if I used the line for the match, and the apropriate replace text with the repl, so it's not pretty, but it works.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Wed 15 Dec 2004 03:52 AM (UTC)  quote  ]
Message
Im not quite sure what all you have to work with, however...

You just have to remove the name (and the | either before or after). Do you already have a table of the names? Just remove the name from the table (which you still have, I believe) and then regenerate the variable.

That regeneration might be easier than trying to find, and then determine what to remove (since if its the first name, youll have to remove the | afterwards, but if its the last, youll have to remove the | beforehand, so regeneration might be better. It will also solve any problems you might have with the data unsynching from each other).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Nick Gammon   Australia  (18,800 posts)  [Biography] bio   Forum Administrator
Date Wed 15 Dec 2004 02:41 AM (UTC)  quote  ]
Message
Quote:


repl = string.gsub (line, "(%a+)", function (w)
         if text [w] then
            return text [w]
         else
            return w
         end -- if
       end) -- function
  for _, v in pairs (styles) do
        ColourTell (RGBColourToName (v.textcolour), 
                RGBColourToName (v.backcolour), 
                (string.gsub (v.text, line, repl)))  
  end



I am glad to hear it is working, but again I think you have combined a couple of my ideas into one.

What you are doing above is two gsubs, one for the entire line, and one per style. I would do one or the other. This will only work if the entire line is a single style (ie. a single colour).

The second gsub is trying to match the entire line, and replacing it with the replacement line, this will only work if the entire line is one style.

- Nick Gammon

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

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Wed 15 Dec 2004 01:02 AM (UTC)  quote  ]
Message
Yes, you can, but I did it that way, don't ask me why. I just did. It took me a few tries to figure out how to get it to work, once I got it working, I left it as it was. No need to change something once it's working.


Flannel, since you showed me how to use the variable trigger, how do I remove a specific name from the variable if I want to remove it from the list?
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Tue 14 Dec 2004 07:00 PM (UTC)  quote  ]

Amended on Tue 14 Dec 2004 07:01 PM (UTC) by Flannel

Message
Why do you need to serialize every 30 seconds? You dont update the list(s) every 30 seconds, do you? Can't you just serialize when you update?

And cant you join them like this:
@variable .. "|%1" or does that not work? Not that it'd offer much of anything, Im just wondering.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Tue 14 Dec 2004 06:10 PM (UTC)  quote  ]

Amended on Tue 14 Dec 2004 06:16 PM (UTC) by David Berthiaume

Message
Woot! Success!

I got it ALL working, just gotta set up the replace script for my skills now.

function textreplace (name, line, wildcards, styles)
 loadstring (GetVariable ("text"))

line = wildcards[1]

repl = string.gsub (line, "(%a+)", function (w)
         if text [w] then
            return text [w]
         else
            return w
         end -- if
       end) -- function
  for _, v in pairs (styles) do
        ColourTell (RGBColourToName (v.textcolour), 
                RGBColourToName (v.backcolour), 
                (string.gsub (v.text, line, repl)))  
  end

end

With that you use:
<triggers>
<trigger
custom_colour="2"
enabled="y"
expand_variables="y"
ignore_case="y"
keep_evaluating="y"
match="(@!replacetext)"
omit_from_output="y"
regexp="y"
repeat="y"
script="textreplace"
sequence="100"
>
</trigger>
</triggers>

And you use:

<aliases>
<alias
match="addtext &quot;*&quot; &quot;*&quot;"
enabled="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>replacetext = "@replacetext" .. "|" .. "%1"
Note ("" .. replacetext)
SetVariable ("replacetext", replacetext)

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

SetVariable ("text", serialize("text"))
</send>
</alias>
</aliases>

Now, When you're me, you have a script serializing every 30 seconds or so, so don't set a replace text that you don't want, cause it can be a pain in the arse to get it out of the table once it's in. Now then, the next thing is to make an alias to do that for us. I'll do that later tonight after work.

One problem left... That'll be fixed in 3.60 when Nick releases it, untill then the variable doesn't seem to want to stay saved when you close the program out.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Tue 14 Dec 2004 05:43 PM (UTC)  quote  ]

Amended on Tue 14 Dec 2004 05:46 PM (UTC) by David Berthiaume

Message
All right, you're right, it's easier:

<aliases>
<alias
match="addtext &quot;*&quot; &quot;*&quot;"
enabled="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>replacetext = "@replacetext" .. "|" .. "%1"
Note ("" .. replacetext)
SetVariable ("replacetext", replacetext)

text ['%1'] = '%2'
</send>
</alias>
</aliases>


That works quite well, I can add into the text {} table with that.

Now all I need to do is link up the 2 pieces of code I have.

This is the code to do the replace and output on the same line:
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


This code is the one that the trigger actually changes the the text:
t =  
  {
  Altair =  'Moe',       ---- Used here as an example
  Ceriloch =  'Larry',   ---- this would actually be an
  Ragnar =  'Curly'      ---- internal table
  }

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)
I just don't know how to link the two together, once that happens, we'll be golden I believe.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Tue 14 Dec 2004 02:27 AM (UTC)  quote  ]

Amended on Tue 14 Dec 2004 02:28 AM (UTC) by David Berthiaume

Message
Tell ya what, lemme get about 15 hours of sleep, and I'll get back to you. It's 10pm EST, Monday night, I've been up since 12pm EST, Sunday afternoon. Getting close to 36 hours up, 12 of it at work, 3 of it traveling, the rest at the computer.

I see what your saying. I don't know if it's better or not. I haven't thought about it, can't really think about it right now... Let me get back to you....

Ok, basically you're doing the same thing I am, just in reverse.

Interesting, it has possibilities. Ultimately, do I write the code for the addtrigger, and be done with it? It's not that much more complicated than writing a Variable. As for CPU and Memory, Athlon XP 2600+, with 512 PC2700 DDR 333Mhz FSB. Not too woried... I can loop up to 10,000 commands at once before I even start to notice a glitch, at 100,000 commands I get a second or two pause, and at 1,000,000 MC locks up, but the computer is just fine.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Tue 14 Dec 2004 01:52 AM (UTC)  quote  ]

Amended on Tue 14 Dec 2004 02:00 AM (UTC) by Flannel

Message
Yes, Serializing, but instead of adding it to a trigger, you can store it in the variable.

The trigger WILL still match with using the variable as match text (see link below). If you want to use your analogy, the funnel is the variable. Well, and the can, for long term storage.

If you store it in the variable, and at the same time you update a second variable of conversions, both of which are overwritten with the serialization, then you wont have to worry about storing it to a variable later, and you can save the world as soon as you finish editing the variables. To make sure you never lose anything.

You wont have to save the world (and write to the variable) every 30 seconds, only when needed, which will save considerable computation time, if you have it happening twice a minute currently.

And then when you open the world, you extract that information to the table, and never worry about losing anything.

That way you only have your table existing in the variables (one for before, one for after) and the script environment. Instead of variables (storing it for long term), your script environment, AND the match text of the trigger.
If you're keeping your variable up to date already, why are you wasting your time with the addtrigger?

Edit:
In case you dont quite understand using the variable with the trigger, you can look at an example here:
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4603

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Tue 14 Dec 2004 01:33 AM (UTC)  quote  ]
Message
Well, you do need an external variable eventually, but either way, when you use the alias to add names and replace text, you also have to add the trigger match to it's own table, else you can't do anything with it.

It's like having a car, and having a tin of gas, but no way to put the gas in the car. That trigger is the tube that lets you put the gas in the car. The car is the trigger, and the alias is the fuel... Hey, that's a pretty nifty analogy.

Anyways, you can do it 1 of 2 ways, with or without a variable. Serializing the tables is easy, I have it happening every 30 seconds(with a world save)

The tricky part of this whole process is translating the table to the script. We got 2 pieces of code, and I don't know how to link them together to get the effect we want.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Tue 14 Dec 2004 01:22 AM (UTC)  quote  ]
Message
But then you have a trigger for each name.
Which you might as well ditch the table for, and hard code it directly into the trigger (no more lookup, just a subroutine which replaces X with Y).

You can have a trigger match ANY name in your table (which is also in your variable) using expand variables and a variable-regexp. So the same trigger matches constantly, and you dont use AddTrigger anywhere.

Oh, youre hard-coding the variable into the trigger. The problem with that is then you have to add the parenthesis to the outsides of the list. Which, is doable.

You would lose the information about the trigger (number of matches and such) which may or may not be an issue.

And I'd imagine setting the variable takes less time than adding a trigger. You'd need to set the MC variable eventually to save your list between sessions (or use a database, but I think a database might be overkill).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Tue 14 Dec 2004 01:09 AM (UTC)  quote  ]
Message
Ok, so you set the variable... how do you match lines of the mud to a variable?

You have to use a trigger.

That's why you have to script an AddTriger

AddTrigger("Textreplace", var.replacetext , "", trigger_flag.Enabled , custom_colour.Custom15, 0, "", "")

make it regexp and lowercase wilds, and what not. Anyways, you have to keep replacing the trigger that matches the replacetext that you want. Otherwise setting up the variable is useless, and like Nick said, we don't even need the variable really, we can script it right into a table and that will speed things up.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Tue 14 Dec 2004 12:51 AM (UTC)  quote  ]
Message
Why are you scripting addtrigger?

Thats why were using the variable, so you can match on anyone inside your list, and then convert. All in one trigger.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Tue 14 Dec 2004 12:34 AM (UTC)  quote  ]
Message
yeah, converting to lowercase works, but annoying when you have to script AddTrigger... *shrugs* Oh well, such is life.

I'm still trying to work out how to combine the first replace text script, and the second example Nick gave us.

I should probably stop for the night, go to bed, and think about it tommorrow morning. when I'm not brain dead tired.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Tue 14 Dec 2004 12:30 AM (UTC)  quote  ]
Message
You can check the "convert wildcards to lowercase" OR you can just cast the name (wildcard, once its passed) to lowercase while you're checking.

Then you'll have to have your match table be all lower case (you convert to lowercase (.lower) when you add it).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[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.


10,885 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]