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