[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]  General
. . -> [Subject]  Toggling "F1, F6 are macros" from within a plugin
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Toggling "F1, F6 are macros" from within a plugin

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


Pages: 1 2  

Posted by KaVir   Germany  (117 posts)  [Biography] bio
Date Wed 03 Nov 2010 09:58 AM (UTC)
Message
My plugin using Accelerator() to redefine the function keys, and this works fine - however I noticed that hitting F1 also attempts to open the windows help.

Currently I inform my users that they need to go to File -> Global Preferences -> General and toggle "F1, F6 are macros". But is there any way to do it automatically from within the plugin?

Wouldn't it make sense to automatically disable the help if you manually override F1 with something else? I can't envision a scenario in which you'd want it to do both.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #1 on Wed 03 Nov 2010 03:02 PM (UTC)
Message
There's no way to change any of the global settings from within a plugin, AFAIK.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by KaVir   Germany  (117 posts)  [Biography] bio
Date Reply #2 on Wed 03 Nov 2010 03:29 PM (UTC)
Message
Is there perhaps a local equivalent then? Something that treats F1/F6 as macros for the current world?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Wed 03 Nov 2010 08:18 PM (UTC)

Amended on Thu 04 Nov 2010 08:32 PM (UTC) by Nick Gammon

Message

db = sqlite3.open(GetInfo (82))  -- open preferences
db:exec 'UPDATE prefs SET value = 1 WHERE name = "F1macro"'
db:close()  -- close


However that only affects the database. You need to close MUSHclient totally and re-open it to have that noticed.

[EDIT]
From version 4.67 onwards then add this line:


utils.reload_global_prefs ()


- Nick Gammon

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

Posted by KaVir   Germany  (117 posts)  [Biography] bio
Date Reply #4 on Thu 04 Nov 2010 09:51 AM (UTC)

Amended on Thu 04 Nov 2010 09:53 AM (UTC) by KaVir

Message
Thanks Nick - so if I understand it correctly, that means F1 would still bring up windows help the first time you used MUSHclient after installing the plugin, but the next time you started MUSHclient it would be working.

Is there any harm in executing the above code each time the plugin is started? Or is there a better way of doing it, some sort of one-time initialisation when the plugin is first added?

Is it perhaps possible to query the database for the value? If so, I could first check if the value is 0, then if the user tries to use F1 I could at least send them a message explaining that they need to close MUSHclient and reopen it.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #5 on Thu 04 Nov 2010 10:32 AM (UTC)
Message
KaVir said:
Is there any harm in executing the above code each time the plugin is started? Or is there a better way of doing it, some sort of one-time initialisation when the plugin is first added?

Is it perhaps possible to query the database for the value? If so, I could first check if the value is 0, then if the user tries to use F1 I could at least send them a message explaining that they need to close MUSHclient and reopen it.

You can just use GetGlobalOption("F1macro") to get the current value of the that option.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by KaVir   Germany  (117 posts)  [Biography] bio
Date Reply #6 on Thu 04 Nov 2010 01:53 PM (UTC)
Message
Handy, thanks!
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Thu 04 Nov 2010 08:34 PM (UTC)
Message
I can see how it would be useful to customize global preferences when distributing pre-made setups. I have added a new script function to the utils table for version 4.67:


db = sqlite3.open(GetInfo (82))  -- open preferences
db:exec 'UPDATE prefs SET value = 1 WHERE name = "F1macro"'
db:close()  -- close

utils.reload_global_prefs ()


Now that will force the global preferences to be updated.

- Nick Gammon

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

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #8 on Thu 04 Nov 2010 08:48 PM (UTC)
Message
Pardon my skepticism, but how is that any better than just creating a SetGlobalOption function? I could actually create a wrapper that does just that:


function SetGlobalOption(name, value)
  name = ("'%s'):format(name:gsub("'", "''"))
  
  if type(value) == "string" then
    value = ("'%s'"):format(value:gsub("'", "''"))
  elseif type(value) == "number" then
    value = tostring(value)
  else
    error("Invalid value type '" .. type(value) .. "'.")
  end
  
  local db = sqlite3.open(GetInfo(82))
  db:exec(('UPDATE prefs SET value = %s WHERE name = %s'):format(value, name))
  db:close()
  
  utils.reload_global_prefs()
end

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Thu 04 Nov 2010 09:09 PM (UTC)
Message
Oh well, my work is done then. :)

I don't really want to encourage plugins to change global options - after all that makes them a little less self-contained.

- Nick Gammon

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

Posted by KaVir   Germany  (117 posts)  [Biography] bio
Date Reply #10 on Fri 05 Nov 2010 09:43 AM (UTC)
Message
Excellent, thanks again. I can understand not wanting to encourage plugins to change global options, but presumably with this new addition I could at least make the change temporary? Eg:


if GetGlobalOption("F1macro") ~= 1 then

  -- set the F1macro option
  db = sqlite3.open(GetInfo (82))  -- open preferences
  db:exec 'UPDATE prefs SET value = 1 WHERE name = "F1macro"'
  db:close()  -- close

  -- update the global preferences
  utils.reload_global_prefs ()

  -- revert the F1macro option, but don't update the global preference again
  db = sqlite3.open(GetInfo (82))  -- open preferences
  db:exec 'UPDATE prefs SET value = 0 WHERE name = "F1macro"'
  db:close()  -- close

end -- if


My players are pretty lazy when it comes to updating (either MUSHclient or the plugin), but I always recommend the latest version for new players, and this change is mainly for their benefit anyway (the existing players will already have manually set the global option themselves).

P.S: On the subject of MUSHclient versions, Nick, you may find this of interest: http://www.godwars2.org/mwi/clients/mushclient - note that this page lists MUSHclient versions by character rather than by player or IP address, but the percentages still give a general overview of which versions are used the most. My plugin currently requires 4.51 or later, and most people still use that version.

[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #11 on Fri 05 Nov 2010 09:46 AM (UTC)
Message
KaVir, if you want to 'revert' the value, do exactly that. Don't turn it off. Or in less cryptic words: save the old value, restore it afterwards.

If someone made the change by choice, you don't want to mess with it and confuse the crap out of them whenever your code runs.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #12 on Fri 05 Nov 2010 10:04 AM (UTC)
Message
Worstje said:

KaVir, if you want to 'revert' the value, do exactly that. Don't turn it off. Or in less cryptic words: save the old value, restore it afterwards.

If someone made the change by choice, you don't want to mess with it and confuse the crap out of them whenever your code runs.

I presume that's why there's an if-check around the block.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #13 on Fri 05 Nov 2010 01:17 PM (UTC)
Message
... Shh. I get to ignore that at my choosing. >.>
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #14 on Fri 05 Nov 2010 08:10 PM (UTC)
Message
KaVir said:

Excellent, thanks again. I can understand not wanting to encourage plugins to change global options, but presumably with this new addition I could at least make the change temporary? Eg:


Yes, very cunning. My psychic powers told me someone might do that, so I left the way open for it.

The only problem is, if one plugin wants F1 to bring up Help, and another plugin wants F1 to NOT bring up help. Then you are stuck, eh?

An alternative would be to ask the player, and then permanently change it. Maybe remember if you asked them so you don't ask every time.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


16,352 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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]