Skip to content

Commit

Permalink
🐛 Fix random.dice trying to convert string values to floats
Browse files Browse the repository at this point in the history
Closes #544
  • Loading branch information
CosmoMyzrailGorynych committed Nov 3, 2024
1 parent 6d0a4e9 commit e4bd50d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/data/ct.libs/random/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Returns a random float value between 0 and x, exclusive.

### `random.dice(dice1,dice2,...diceN)`
Returns a random given argument.
When given just one string value, the string will be split by `,` separator and a random item will be returned.

### `random.range(x1, x2)`
Returns a random float value between `x1` and `x2`, exclusive.
Expand Down
9 changes: 5 additions & 4 deletions app/data/ct.libs/random/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ Object.assign(random, {
dice(...variants) {
const dices = processRandomInput(variants);
if (Array.isArray(dices) && dices.length > 0) {
const result = dices[Math.floor(Math.random() * dices.length)];
const parsedResult = parseFloat(result);
return isNaN(parsedResult) ? result : parsedResult;
return dices[Math.floor(Math.random() * dices.length)];
}
return null;
},
Expand Down Expand Up @@ -51,7 +49,10 @@ Object.assign(random, {
return Math.random() * 360;
},
coord() {
return [Math.floor(Math.random() * camera.width), Math.floor(Math.random() * camera.height)];
return [
Math.floor(Math.random() * camera.width),
Math.floor(Math.random() * camera.height)
];
},
chance(x, y) {
if (y) {
Expand Down
6 changes: 3 additions & 3 deletions app/data/ct.libs/random/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ interface IPoint {
declare function random(x: number): number;
declare namespace random {
/**
* Returns random argument from comma separated arguments (without spaces):
* Numbers will return float. Words will return string. These can be mixed.
*
* Returns random argument from comma separated arguments (without spaces),
* or a random argument when given several arguments.
*
* @catnipName random from list
* @catnipName_Ru случайное из списка
*/
Expand Down

0 comments on commit e4bd50d

Please sign in to comment.