#registering multiple keybindings
1 messages · Page 1 of 1 (latest)
Let's continue here then
This seems to be the current code:
for (const i in preconfigkeys) {
console.log(`${i}${preconfigkeys[i].keymodifiers}`);
game.keybindings.register("token elevator", `elevation${i}`, {
name: `Change token elevation by ${preconfigkeys[i].elevationchange}`,
editable: [{
key: "Backquote",
modifiers: preconfigkeys[i].keymodifiers
}],
onDown: () => {elevation(i);}
})
I would do the following instead:
const preconfigkeys = [
{ elevationchange: -10, keymodifiers: ["Shift", "Control"] },
{ elevationchange: -5, keymodifiers: ["Control"] },
{ elevationchange: 0, keymodifiers: ["Shift", "Alt"] },
{ elevationchange: 5, keymodifiers: [] },
{ elevationchange: 10, keymodifiers: ["Shift"] },
];
for (const preconfigkey of preconfigkeys) {
game.keybindings.register("token elevator", `elevation${preconfigkey.elevationchange}`, {
name: `Change token elevation by ${preconfigkey.elevationchange}`,
editable: [
{
key: "Backquote",
modifiers: preconfigkey.keymodifiers,
},
],
onDown: () => {
elevation(i);
},
});
}
also, module names probably shouldn't have spaces in them, so please use "token-elevator" instead of "token elevator".
also applies to the name in the module.json etc.
Hi, I am back. I will try your suggestion. Thanks for the hint on the module name, I did not look into these things yet, because at the moment this is still a worldscript that hooked into F-for-flatfooted. Using its own name puts it under General now.
"Uncaught SyntaxError: missing ) after argument list"
Ah, the hooks.on (
I was already trying around how to get this: keymodifiers: ["Shift", "Control"] },
and this together modifiers: preconfigkey.keymodifiers,
But at this point I only just learned that Shift+Control does not work and did not wrap my head around where which quotes have to be.
So this is a welcome simplification of the problem
Your solution also allows for the "5" case to be empty [], which does not throw an error, while the old `` solution did.
Next I will incorporate some suggestions by Varriount, including renaming the function to a verb instead of a noun.
I am astounded that [] seems to be a string in the array despite missing quotes. This is something I have to look up with JS.
it's not a string, it's an array
an empty array
I think I don't completely understand what you mean
Me neither, because I am not fluent in the correct terminology yet. I meant that the single array object uses literally with all its [] and "" and everything without it having to be put into quotes by itself. It's not a number and seemingly it's not a string, but it includes everything as if it were a string for the sake of including all characters.
All the examples I found when looking at "array of objects" either used quotes for anything with characters or use no quotes for numbers. So the keymodifiers: ["Shift", "Control"] format came as a pleasant surprise.
Currently reading up on where I should put semicolons and where I "might" not have/want to.
To clean this up. Also fixed the " elevation(i);" still being in there (with is invalid after removing the for i loop part).
an array is just a list of things. you can have an array of strings (["a", "b", "foobar"]), an array of numbers ([1, 2, 42]), or whatever else you want
Now that the modifiers part became so much easier to handle I code the reset to 0 part back in, turn it into a module and include localization.
The "whatever else you want" part including such combinations as ["xyz012"] was the surprising part.
And I assumed that internally that would still be a string of chars then.
you can also mix the stuff inside the array, e.g. [0, "foobar", false, {key: "value"}, ["another array inside"]]
nope, not at all
The nice part about this is that this "whatever" is then literally forwarded to the "modifiers: preconfigkey.keymodifiers," line, which again I did not anticipate. Some hours ago I was contemplating that something akin to macro assember would be useful in this situation where the compiler inserts the literal part. But obviously the array already handles just that.
Nice stuff.
@pure crystal @tired kayak @magic magnet Thanks again for the hints and code snippets. The "Token Elevation" module is officially released and available in Foundry's installer now. The license is practically Public Domain.
Great!
(By „practically public domain“, you mean as close as possible to public domain as copy right allows in your legislation?)
I used the "MIT No Attribution" license, which is the equivalent to "Public Domain" while still being a real license even in juristictions that do not acknowledge the "Public Domain" moniker.
Aka, no attribution, license or copyright notice required.
It is also equivalent to the 0BSD (Zero-Clause BSD) license, but using the more "licenses for dummies" wording of MIT.
And yes, among learning JS in general (+ESlint linting and automating according to style guides) and module coding in detail I also studied a couple of licenses,their implications and detailed differences. 😉
Less sleep than usual, though... zzzzZZ
Generally:
- If you truly don't care what is done with your code, use MIT or BSD
- If you want to prevent companies from taking your code, modifying it, then selling the modified code, use GPL. Though this makes people in general less likely to use it, especially if it's a library.