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 ➜ Using ATCP in scripts

Using ATCP in scripts

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


Posted by Curious2   (47 posts)  Bio
Date Sun 25 Jan 2009 11:49 PM (UTC)
Message
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.

Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 26 Jan 2009 12:04 AM (UTC)

Amended on Mon 26 Jan 2009 12:05 AM (UTC) by Nick Gammon

Message
Plugins are supposed to be self-contained, however there are ways of getting data to and from them.



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Curious2   (47 posts)  Bio
Date Reply #2 on Mon 26 Jan 2009 12:18 AM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Mon 26 Jan 2009 01:40 AM (UTC)

Amended on Mon 26 Jan 2009 01:48 AM (UTC) by Nick Gammon

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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 26 Jan 2009 02:28 AM (UTC)
Message
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))

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Curious2   (47 posts)  Bio
Date Reply #5 on Sun 01 Feb 2009 04:52 PM (UTC)
Message
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.
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #6 on Sun 01 Feb 2009 05:47 PM (UTC)
Message
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. :)
Top

Posted by Isuka   (9 posts)  Bio
Date Reply #7 on Mon 09 Feb 2009 02:17 AM (UTC)
Message
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.
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.


21,935 views.

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.