Using ATCP in scripts

Posted by Curious2 on Sun 25 Jan 2009 11:49 PM — 8 posts, 31,717 views.

#0
How do I get ATCP to work with my script file?

I tried using one of the plugins, but that doesn't do me much good because I can't get my stat info.

I installed these plugins:

http://www.gammon.com.au/forum/bbshowpost.php?id=8915

I need to use all that information in my script file for drinking health/mana and so on.

I noticed a couple threads regarding how you can't pass the data back and forth easily. I find this to be a problem. I guess I just don't understand it and haven't really worked with plugins yet.

http://www.gammon.com.au/forum/bbshowpost.php?id=7708


Maybe someone can explain to me how I can pass this information to my scripts. Every time I receive the Char.Vitals info I want to update my stats table. Then use that for my auto sipper and other things. Basically I want to use the stats table in my regular script file.

Am I going to have to just put all my stuff in a plugin or what?

I'm sure this seems easy to people who have used Mushclient a long time. I'm used to zmud/cmud. In cmud this kind of support was built in and I just had a telnet 200 trigger that captured char.vitals info. Of course there are a lot of bugs though since he is still working on cmud which is why I thought I would try out Mushclient. I like Mushclient so far, but some things confuse the heck out of me. I'm not a programmer and I can tell that some of you are.

Australia Forum Administrator #1
Plugins are supposed to be self-contained, however there are ways of getting data to and from them.

Amended on Mon 26 Jan 2009 12:05 AM by Nick Gammon
#2
Ok I'll read through all that. Will this slow me down any though having to pass the info all over the place? What I mean is would it just be faster to use a prompt trigger and get my info off the prompt instead of having to get char.vitals in the plugin which updates the stats table then pass that to the script file? I prefer to use a short prompt though and char.vitals contains all the info and is much faster.

The main problem is I need everything built for speed. I'm even wondering if I am going about some of my scripting right using the send to script after omit stuff. IRE combat you need serious speed.

Why can't you just put the ATCP stuff in your main script file?
Australia Forum Administrator #3
Quote:

Why can't you just put the ATCP stuff in your main script file?


I think it uses the OnPacketReceived plugin callback, to process the raw data in the MUD input, and that only works in plugins.


Quote:

Will this slow me down any though having to pass the info all over the place?


MUSHclient is pretty fast. To reconfirm that I wrote the test below.

To pump test data through the client I used a test file I had from my benchmarks page, the file being:

http://www.gammon.com.au/mushclient/high.txt

This file contains 5,378 lines of MUD example output, including colour codes, so it has to do all the ANSI decoding as it processes it.

The test below generates 1,000 random triggers (matching on a 20-character string like "[McN`pNrCHzDXiHfxNwF"). These triggers will not match, thus forcing MUSHclient to evaluate 1,000 triggers per line, for 5,378 lines.

In addition I added the following trigger 10 times:


<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="a"
   regexp="y"
   send_to="12"
   sequence="200"
  >
  <send>something = something + 1</send>
  </trigger>
</triggers>


This matches 3,788 lines (because most lines have "a" in them). This does an addition using send-to-script. Thus for all of the 3,788 matching lines, it has to do 3,788 * 10 script calls (a total of 37,880 send-to-script).

The sequence number of 200 makes sure it is tested last, after the 1000 other triggers.


require "addxml"

-- make 1,000 random triggers

for i = 1, 1000 do

  local match = ""

  for k = 1, 20 do
    match = match .. string.char (math.random (string.byte ("A"), string.byte ("z")))
  end -- random word

  addxml.trigger {
    enabled = 'y',
    sequence = '100',
    match = match,
    group = "test",
    }

end -- for adding triggers

something = 0  -- for the addition test

-- timing test

tstart = os.time ()

-- simulate MUD input

for line in io.lines ("high.txt") do
  Simulate (line .. "\n")
end 

tend = os.time ()
print ("Time taken = ", os.difftime (tend , tstart))


So what is the result of all that?


Time taken =  8


So the whole thing took 8 seconds (which included loading the high.txt file from disk). Now if you divide 5,378 lines by 8 you get 672.

In other words, it was able to keep up with processing 672 lines per second processing 1,000 non-matching triggers, and 10 matching triggers in most lines.

Considering that a screenful of data is around 20 lines, I think the trigger matching, and scripting speed, easily would keep up with MUD output, even with a lot of script processing, and not slow down significantly.

I ran this test in the Immediate window (with the file high.txt in the same directory as MUSHclient).

Be warned if you run it multiple times you will get longer figures, as it will add 1000 random triggers every time, and thus trigger processing will take longer.
Amended on Mon 26 Jan 2009 01:48 AM by Nick Gammon
Australia Forum Administrator #4
Oh, and adding the triggers was fast too. I added 3,000 triggers in this test in only 1 second:


require "addxml"

tstart = os.time ()

for i = 1, 3000 do

  local match = ""

  for k = 1, 20 do
    match = match .. string.char (math.random (string.byte ("A"), string.byte ("z")))
  end -- random word

  addxml.trigger {
    enabled = 'y',
    sequence = '100',
    match = match,
    group = "test",
    }

end -- for adding triggers


tend = os.time ()
print ("Time taken = ", os.difftime (tend , tstart))
#5
Should I just convert everything to a plugin so I can use the ATCP plugin data?

I need to use the stats table because I already had that incorporated thoughout my scripts and in some trigger scripts. Wouldn't that be easier than passing crap back and forth with an alias?

Sorry if I sound stupid. I'm pretty new to MUSHclient and not used to the interface at all. I'm not sure the best way to go about things yet. Basically I want everything to process as fast as possible.
Netherlands #6
From my own scripting-heavy experiences, I can tell you that you shouldn't worry about speed. Unless you do something wrong from a logic perspective (e.g. do something like 'a = a + 1' a thousand times rather than a = a + 1000), you have nothing to worry about.

Premature optimisation is the root of all evil. :)
#7
It is possible to get a plugin to simply use a global alias by using the world.Execute command. Therefor you could put an alias in your world file that calls SetVariable, and pass to it the name of the variable and the value to set it to. Then, from the plugin, just execute the alias.

<aliases>
<alias
match="^setvar (\w+) (\w+)$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable("%1","%2")</send>
</alias>
</aliases>

and then in your plugin do:
Execute("your_variable_name", "value_to_pass")

I've gotten this to work, using Lua, to parse ATCP information correctly from someone elses plugin.