I am absolutely terrible at math so I'm not even sure this is the correct term. What I am trying to do is to divide a number and only get the quotient, not the remainder

```
window.randomnumber = function(min, max) {
return Math.floor(Math.random() * (max + 1 - min)) + min;
};
@set baseMANA = 9
@set MANA = 2
[[ROLL]]
[[ROLL]]:
set ("MANA_regen_roll", randomnumber(1,100));
MANA_regen_roll = {MANA_regen_roll}
{@[email protected]}
{@MANA_regen/[email protected]_regen_roll}
MANA_regen = {MANA_regen}
{@[email protected]_regen}
MANA = {MANA}
```

Here for example, if MANA_regen_roll = 68, the MANA regenerated will be something stupid like 0.1323529411764706

I would much rather it was rounded to 1

`Math.floor`

or `Math.ceiling`

to round a number to the integer part. "floor" rounds down (taking the integer part and discarding the remainder), while "ceiling" rounds up. I notice that your randomnumber function already uses Math.floor; otherwise it would return a random number anywhere from 1.00000… to 100.99999…

How would one use this function? I have very little experience in Javascript, and found a few examples online giving very simple examples such as:

```
var a = Math.ceil(0.60);
```

Here's how I instinctively tried to integrate it (again with nearly 0 knowledge of javascript):

```
set ("MANA", Math.ceiling(MANA));
```

Just before the last line in my first post.

Thanks for the help!

Maybe an easier solution is if there is an operation similar to %= in squiffy that I'm not aware of?

All right, update!

I used what little brain I have to try to find a solution on my own, and while it's not ideal yet, it *technically* works ^_^

Here's the new code, and I'll explain what I don't like about it:

```
window.randomnumber = function(min, max) {
return Math.floor(Math.random() * (max + 1 - min)) + min;
};
window.ceiling = function(hehe) {
return Math.ceil(hehe);
};
@set baseMANA = 250
@set MANA = 0
set ("MANA_regen_roll", randomnumber(1,100));
MANA_regen_roll = {MANA_regen_roll}
{@[email protected]_regen_roll}
{@MANA_regen_calc/=100}
{@MANA_regen_calc*[email protected]}
+++ye
var eh = squiffy.get("MANA_regen_calc")
set ("MANA_regen", ceiling(eh));
{@[email protected]_regen}
MANA = {MANA}
```

Now, the "problem" I have with this is due to the fact that in squiffy all javascript code has to be at the beginning of a section, you can't place it between squiffy code (otherwise it'll just return as plain text, even with the indentation), which is why I have a continue link (+++ye) which I don't really like.

If anyone has an idea how to make this work in one section, I'd be happy to hear it. Otherwise I can perfectly work with this, thanks again @mrangel for pointing me in the right direction!

I don't know Squiffy, and it's hard to tell why you're using so many temporary variables. Wouldn't a single block of javascript work?

```
window.randomnumber = function(min, max) {
return Math.floor(Math.random() * (max + 1 - min)) + min;
};
@set baseMANA = 250
@set MANA = 0
var mana_regen_roll = randomnumber (1, 100);
set ("MANA_regen_roll", mana_regen_roll);
var mana_regen_calc = mana_regen_roll;
mana_regen_calc *= squiffy.get("baseMANA");
mana_regen_calc /= 100;
mana_regen_calc = Math.ceil (mana_regen_calc);
set ("MANA_regen", mana_regen_calc);
{@[email protected]_regen}
MANA_regen_roll = {MANA_regen_roll}
MANA = {MANA}
```

or even:

```
window.randomnumber = function(min, max) {
return Math.floor(Math.random() * (max + 1 - min)) + min;
};
@set baseMANA = 250
@set MANA = 0
var mana_regen_roll = randomnumber (1, 100);
set ("MANA_regen_roll", mana_regen_roll);
var mana_regen = Math.ceil(squiffy.get("baseMANA") * mana_regen_roll / 100);
set ("MANA", squiffy.get ("MANA") + mana_regen);
MANA_regen_roll = {MANA_regen_roll}
MANA = {MANA}
```

I guess I was too scared to use so much js since I have very little knowledge in it (and coding in general), but your second script works fantastic!

Thank you so much for your help, which even gave me a better understanding of how javascript works! (now I guess the next step is to actually learn how to code in it :P )

Log in to post a reply.