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

Gammon Forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Suggestions
. . -> [Subject]  Remember commands from the execute buffer between sessions
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Remember commands from the execute buffer between sessions

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


Posted by Kahenraz   (42 posts)  [Biography] bio
Date Fri 16 Sep 2016 11:37 PM (UTC)
Message
It would be nice if a configurable amount of commands last entered into the execute buffer could be remembered between sessions.

Sometimes I have aliases setup for testing plugins and I want to close the world and reconnect for testing. But then I lose my buffer history where I had some tests for easy access with the up arrow.

It would help a lot for debugging if the last few commands could be saved in the world file and reloaded once reopened.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 17 Sep 2016 02:56 AM (UTC)

Amended on Sat 17 Sep 2016 03:05 AM (UTC) by Nick Gammon

Message
You can serialize any data (including tables) into a string. See: http://www.gammon.com.au/forum/?id=4960

Now, given that, you can make a world function for "on world save" (see the Scripting configuration tab). In that function you can find some or all of the command history. See:

Template:function=GetCommandList GetCommandList

The documentation for the GetCommandList script function is available online. It is also in the MUSHclient help file.



Now, given that table of commands, serialize that into a variable, and then that variable will be saved when you save the world (or write it to a file if you want to not bother saving the world file).

Then next time you start the client you can put things back into the command history with SetCommand and PushCommand:

Template:function=SetCommand SetCommand

The documentation for the SetCommand script function is available online. It is also in the MUSHclient help file.



Template:function=PushCommand PushCommand

The documentation for the PushCommand script function is available online. It is also in the MUSHclient help file.



Example code in script file:


local CommandsFile = GetInfo (66) .. "commands.txt"  -- MUSHclient directory
require "serialize"
  
function OnWorldSave ()
  local f = assert (io.open (CommandsFile, "w"))
  f:write ("commands = " .. serialize.save_simple (GetCommandList (100) or {} ))
  f:close ()
end -- OnWorldSave

function OnWorldOpen ()
  local f = io.open (CommandsFile, "r")
  if not f then
    return
  end -- of no file found

  -- read file in 
  local commandsTable = assert (f:read ("*a"))  -- read all of it
  f:close ()

  -- load into "t.commands"
  local t = {}  
  setfenv (assert (loadstring (commandsTable)), t) ()

  -- push into command history
  
  for i = #t.commands, 1, -1 do
    SetCommand (t.commands [i])
    PushCommand ()
  end -- for
  
  ColourNote ("orange", "", "Loaded " .. #t.commands .. 
              " commands into command history")
end -- OnWorldOpen


You need to put "OnWorldOpen" and "OnWorldSave" into the appropriate boxes in the scripting configuration dialog.

This saves the last 100 commands. Change the "100" in the code to something else if you want.

- Nick Gammon

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

Posted by Kahenraz   (42 posts)  [Biography] bio
Date Reply #2 on Sat 17 Sep 2016 03:17 AM (UTC)
Message
I'm still learning the nuances of Lua and Mush but I'm picking it up pretty fast. The scripting capabilities really make this client amazing.

Thanks a lot for the code and your advice. :)
[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.


1,869 views.

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 FutureQuest]