danielpa Posted July 25, 2019 Share Posted July 25, 2019 I see a lot of mods generate a list of keys when they want to add a keybinding like so: local FIRST_NUMBER = 48 local FIRST_LETTER = 65 for i = 1, 10 do local ch = string.char(FIRST_NUMBER + i - 1) keyslist[i] = {description = ch, data = ch} end for i = 11, 36 do local ch = string.char(FIRST_LETTER + i - 11) keyslist[i] = {description = ch, data = ch} end Is there a better way to assign a keybinding for your mod? Link to comment Share on other sites More sharing options...
Ultroman Posted July 25, 2019 Share Posted July 25, 2019 That code generates a list of possible keys with their proper names, so people can choose which key they want from the list in the mod settings. I mean...what is it you want to improve upon? Link to comment Share on other sites More sharing options...
danielpa Posted July 25, 2019 Author Share Posted July 25, 2019 Like the selector don't starve provides for changing his keybindings, like attack, rotate etc... Link to comment Share on other sites More sharing options...
danielpa Posted July 25, 2019 Author Share Posted July 25, 2019 Anyway, here is a little improvement on the code, in case someone finds it useful function generateKeys(result, from, to) local s = string.byte(from, 1) local e = string.byte(to, 1) do local i = s while i <= e do local key = string.char(i) result[#result + 1] = {description = key, data = key} i = i + 1 end end end string = "" local keys = {} generateKeys(keys, "0", "9") generateKeys(keys, "a", "z") Link to comment Share on other sites More sharing options...
Ultroman Posted July 25, 2019 Share Posted July 25, 2019 1 hour ago, danielpa said: Like the selector don't starve provides for changing his keybindings, like attack, rotate etc... Yeah, I don't know if you can influence the UI like that. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now