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
➜ Lua
➜ Saving Accelerator
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Ruckinfok
(7 posts) Bio
|
| Date
| Mon 21 Feb 2011 06:12 PM (UTC) Amended on Mon 21 Feb 2011 06:35 PM (UTC) by Ruckinfok
|
| Message
| Ok, so I'm making a plugin to use accelerator to keybind some stuff, and I read http://www.gammon.com.au/forum/?id=4960, but I'm having trouble getting it to save my state. Where do I put all that code? What is the name of the accelerator table? I will have to change all occurances of "what" with that name right? Thanks in advance.
Edit: I am getting the following error:
Compile error
Plugin: Accelerator (called from world: ansalon)
Immediate execution
[string "Plugin"]:181: ')' expected (to close '(' at line 180) near ','
Error context in script:
177 :
178 : lua_reserved_words = {}
179 :
180 : for _, v in (
181*: "and", "break", "do", "else", "elseif", "end", "false",
182 : "for", "function", "if", "in", "local", "nil", "not", "or",
183 : "repeat", "return", "then", "true", "until", "while"
184 : ) do lua_reserved_words [v] = true end
185 :
[WARNING] \\QUADS\worlds\plugins\Accelerator.xml
Line 54: Error parsing script (Cannot load) | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Mon 21 Feb 2011 07:18 PM (UTC) |
| Message
| In lines 181 and 184 the ( and ) should be { and } (curly brackets).
However you absolutely should not even be using that code directly.
You just use the existing module. You just add a couple of lines to your plugin, as described near the bottom of that thread, eg.
require "serialize" -- needed to serialize table to string
function OnPluginSaveState ()
-- get accelerator table
local t = AcceleratorList () or {} -- use empty table if no list
SetVariable ("accelerators", "accelerators = " .. serialize.save_simple ( t ))
end -- function OnPluginSaveState
Then in OnPluginInstall you are going to have to put the accelerators back. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Ruckinfok
(7 posts) Bio
|
| Date
| Reply #2 on Mon 21 Feb 2011 07:57 PM (UTC) Amended on Mon 21 Feb 2011 08:09 PM (UTC) by Ruckinfok
|
| Message
|
Nick Gammon said:
Then in OnPluginInstall you are going to have to put the accelerators back.
What do you mean by this?
This is what I have now:
<script>
function OnPluginInstall()
Accelerator ("alt+numpad4", "flee west")
Accelerator ("alt+numpad6", "flee east")
Accelerator ("alt+numpad8", "flee north")
Accelerator ("alt+numpad2", "flee south")
SetVariable ("accelerator", serialize ("accelerator")) --> serialize accelerator table
end
require "serialize" -- needed to serialize table to string
function OnPluginSaveState ()
-- get accelerator table
local t = AcceleratorList () or {} -- use empty table if no list
SetVariable ("accelerators", "accelerators = " .. serialize.save_simple ( t ))
end -- function OnPluginSaveState
</script>
I took out the SetVariable ("accelerator", serialize ("accelerator")) part, and I stopped getting errors, but it still isn't saving. I imagine you're telling me I need to "load" my set of accelerators during my onplugininstall function, but how do I do this? Also, will it save it individually for each world file, like usual for variables (I imagine yes)?
Sorry, I'm so new to this! | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Tue 22 Feb 2011 12:28 AM (UTC) |
| Message
| | OK, let's go back a step. Why do you want to save them? You just have the four as far as I can see, and they will automatically be installed. How do others get created? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Ruckinfok
(7 posts) Bio
|
| Date
| Reply #4 on Tue 22 Feb 2011 12:40 AM (UTC) Amended on Tue 22 Feb 2011 12:41 AM (UTC) by Ruckinfok
|
| Message
|
Nick Gammon said:
OK, let's go back a step. Why do you want to save them?
First of all, I use multiple world files for multiple characters, and would like to have separate accelerators set for different characters for the same keys (without having to manage multiple files).
Second of all, I intend to share this plugin with others. I like to try to make plugins I share with others manageable without having to edit the text in the xml file.
Nick Gammon said:
You just have the four as far as I can see, and they will automatically be installed. How do others get created?
I use the following aliases to manage them:
<alias
match="bind '*' '*'"
enabled="y"
sequence="100"
send_to="12"
><send>
Accelerator("%1", "%2")
Note("%2 bound to keystroke %1")
SaveState ()
</send></alias>
<alias
match="bindlist"
enabled="y"
sequence="100"
send_to="12"
><send>
for _, v in pairs (AcceleratorList ()) do
Note (v)
end
SaveState ()
</send></alias>
I put those 4 in because I was certain I would use them across all characters, and because I was getting error messages about not having any accelerators, so I supplied some on install so squash the error. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Tue 22 Feb 2011 05:47 AM (UTC) Amended on Tue 22 Feb 2011 05:48 AM (UTC) by Nick Gammon
|
| Message
| OK, I see. Well the saving part is fine. If you check your variable "accelerators" in the GUI interface (after saving the world) you should see something like this:
accelerators = {
[1] = "Alt+Numpad2 = flee south",
[2] = "Alt+Numpad4 = flee west",
[3] = "Alt+Numpad6 = flee east",
[4] = "Alt+Numpad8 = flee north",
}
Now, we need to process that in OnPluginInstall.
Add the code below in bold (and take out your line about setting the variable):
function OnPluginInstall()
Accelerator ("alt+numpad4", "flee west")
Accelerator ("alt+numpad6", "flee east")
Accelerator ("alt+numpad8", "flee north")
Accelerator ("alt+numpad2", "flee south")
-- convert string back into Lua table
assert (loadstring (GetVariable ("accelerators") or "")) ()
-- if found, process it
if accelerators then
for k, v in ipairs (accelerators) do
local key, action = string.match (v, "^(%S+) = (.*)$")
if key then
Accelerator (key, action)
end -- if matched
end -- for
end -- if
end -- OnPluginInstall
That converts the string variable back into a table, and then goes through the table, converting each entry into keyname/action. Then it does an "Accelerator" on each of those. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Ruckinfok
(7 posts) Bio
|
| Date
| Reply #6 on Tue 22 Feb 2011 12:36 PM (UTC) |
| Message
| | Thanks, this works flawlessly! | | 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.
26,700 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top