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 ➜ General ➜ Lets start the conversion.

Lets start the conversion.

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


Pages: 1  2  3  4  5 

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #60 on Tue 14 Dec 2004 01:33 AM (UTC)
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.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #61 on Tue 14 Dec 2004 01:52 AM (UTC)

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.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #62 on Tue 14 Dec 2004 02:27 AM (UTC)

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.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #63 on Tue 14 Dec 2004 05:43 PM (UTC)

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.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #64 on Tue 14 Dec 2004 06:10 PM (UTC)

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.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #65 on Tue 14 Dec 2004 07:00 PM (UTC)

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.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #66 on Wed 15 Dec 2004 01:02 AM (UTC)
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?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #67 on Wed 15 Dec 2004 02:41 AM (UTC)
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
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #68 on Wed 15 Dec 2004 03:52 AM (UTC)
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.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #69 on Wed 15 Dec 2004 06:23 AM (UTC)
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.
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.


149,635 views.

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

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.