
Try adding "step=0.1" or "step=0.01" (depending on how fractional you want to go) to your input syntax.
<input type="number" name="attr_whatever" step="0.1">
Finderski said:
Try adding "step=0.1" or "step=0.01" (depending on how fractional you want to go) to your input syntax.
<input type="number" name="attr_whatever" step="0.1">
Thanks Finderski....I will try that :D
That worked perfectly :D
Finderski said:
Try adding "step=0.1" or "step=0.01" (depending on how fractional you want to go) to your input syntax.
<input type="number" name="attr_whatever" step="0.1">
Do you know a way to prevent a player from entering fractional numbers as inputs?
You could use a sheet worker. For the field in question, on change evaluate the number and either round it to the nearest whole number (something like Math.round(), I think?) or just parse it to an int (parseInt()) and then write it back to the field.
That’s the only way I know of for certain, though there are cleverer people who prowl these forums who might have a better/easier solution...
Finderski said:
Or maybe try step=1
Tried the "step=1"....didn't do anything....hmmmm *thinking*
Also tried "step=1.0"....same result....
If step=1 doesnt work, you'll need to use a sheet worker.
Finderski said:
You could use a sheet worker. For the field in question, on change evaluate the number and either round it to the nearest whole number (something like Math.round(), I think?) or just parse it to an int (parseInt()) and then write it back to the field.
That’s the only way I know of for certain, though there are cleverer people who prowl these forums who might have a better/easier solution...
It looks like Ray just wants to make sure player-entered numbers are integers, so no need for rounding, just use parseInt. This can make the sheetworker pretty short. For an attribute named 'whatever'
on("change:whatever", function() {
getAttrs(["whatever"], function(values) { setAttrs({ whatever: parseInt(values.whatever, 10)||0 }); }); });
If the player enters a non-integer number, when they leave the input (by tabbing out or clicking anywhere else), the number will change to an integer.
If you want to do it for a group of attributes, here's a simple way to do it:
['whatever', 'another', 'attribute'].forEach(att => {
on(`change:${att}`, function () {
getAttrs([att], function (values) {
setAttrs({
[att]: parseInt(values[att], 10) || 0
});
});
});
});
Only the first line needs changing. Just change the array ['whatever', 'another', 'attribute'] to match whatever attribute names you want processed.
This is the simplest example of a Universal Sheet Worker I've made yet, so could be informative on how to make them. Compare the two sheet workers and see what needed to be changed.
GiGs said:
If step=1 doesnt work, you'll need to use a sheet worker.
It looks like Ray just wants to make sure player-entered numbers are integers, so no need for rounding, just use parseInt. This can make the sheetworker pretty short. For an attribute named 'whatever'
on("change:whatever", function() {
getAttrs(["whatever"], function(values) { setAttrs({ whatever: parseInt(values.whatever, 10)||0 }); }); });If the player enters a non-integer number, when they leave the input (by tabbing out or clicking anywhere else), the number will change to an integer.
If you want to do it for a group of attributes, here's a simple way to do it:
['whatever', 'another', 'attribute'].forEach(att => {
on(`change:${att}`, function () {
getAttrs([att], function (values) {
setAttrs({
[att]: parseInt(values[att], 10) || 0
});
});
});
});Only the first line needs changing. Just change the array ['whatever', 'another', 'attribute'] to match whatever attribute names you want processed.
This is the simplest example of a Universal Sheet Worker I've made yet, so could be informative on how to make them. Compare the two sheet workers and see what needed to be changed.
Spot on with the interpretation GiGs...I want to prevent players assigning fractions of experience points in improving characteristics. The exception being COM and END which cost 0.5xp's per characteristic point, but I deal with those by rounding.
Thanks for the sheetworkeer solutions..I will play with them and see which works best.
Many Thanks :D