sugarcube-2
sugarcube-2 copied to clipboard
Minimum and Maximum for <<numberbox>>
Is your feature request related to a problem? I have witnessed roughly 5~ authors having trouble with the numberbox macro, for they would love to have a minimum and maximum, to prevent players from entering ridiculous numbers. So a limiter would be nice.
Describe the solution you'd like. I want to show you the following example of how I "bypassed" the traditional way:
Hereby the code:
<<script>>
$(`<span />`)
.wiki(`<<numberbox "$Age" 1>>`)
.find("input").attr({
"min": 1,
"max": 99
}).appendTo(this.output);
// change $age to your variable
// change "min" 1 to your minimum
// change "max" 99 to your maximum
<</script>>
<<done>>
<<script>>
document.getElementById("numberbox-age").addEventListener("change", function() {
let number = Number(this.value);
if (number < 1) this.value = 1;
if (number > 99) this.value = 99;
});
// change 'numberbox-age' to 'numberbox-nameofyourvariable'
// change both 1 to your minimum
// change both 99 to your maximum
<</script>>
<</done>>
Additional context. Maybe the macro could work like this (which makes it rather lengthy):
<<numberbox "$answertolife" 42 1 100 "Truth" autofocus>>
A numberbox to change the variable answertolife
starting at 42, with a minimum of 1, with a maximum of 100, forwarding to the passage 'Truth' and autofocus.
FYI, I believe the <<numberpool>>
addon macro set does this.
FYI, I believe the
<<numberpool>>
addon macro set does this.
I see what you mean, in that case, why isn't the macro a default one, and rather an add-on? If it stays an add-on, could there be a little note, like: "If you are looking for a way to have a minimum and maximum, use the <<numberpool>>
"