@inc from a variable

Padrinos
10 Jan 2016, 19:53
With the help of other posts, I figured out how to have something give a random number based on a set range, but is there is way to have that random number added to something? As in @inc reputation 2
This is what I have, but cant get it to add up. Thanks for any help.

var randomnumber = function rng(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}

set ("earnRep", randomnumber(2,6));

<u>Reputation increases by {earnRep}</u><br>
@inc reputation {earnRep}<br>
<b>Reputation = {reputation}</b><br>

Alex
12 Jan 2016, 18:57
You would need to use JavaScript for this, as @inc only handles numbers.

Try this after your code for setting earnRep:


set ("reputation", get("reputation") + get("earnRep"));

Padrinos
18 Jan 2016, 23:33
Thanks Alex, that worked as far as adding the random number to the reputation, but the @inc shows.

Here is what I typed:
[[rep]]:
var randomnumber = function rng(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}

set ("earnRep", randomnumber(2,6));
set ("reputation", get("reputation") + get("earnRep"));

<u>Reputation increases by {earnRep}</u><br>
@inc reputation {earnRep}<br>
<b>Reputation = {reputation}</b><br>

Here is how it displayed:
Reputation increases by 4
@inc reputation 4
Reputation = 17

So everything added correctly, just displays the @inc reputation #

Alex
19 Jan 2016, 10:50
You don't need the @inc line in there any more, you're increasing the reputation score using JavaScript now.

Padrinos
11 Feb 2016, 16:55
Alex, you are awesome. Thank you very much