Concatenating instead of adding.
Rockenden
10 Jul 2015, 12:53I'm expanding my simple combat system into something a bit less simple and adding skill modifiers but I've hit a bit of a stumbling block. When I use the + operator to add a skill modifier to a die roll the 2 numbers are concatenated instead of added and producing a total.
Any help would be gratefully received.
Any help would be gratefully received.
set("RatHealth", "4");
set("RatCombatSkill", "1");
A large rat launches itself into the air, broken yellow teeth flashing.
<b>RAT</b><br>
COMBAT SKILL:1<br>
STRENGTH:1<br>
HEALTH:4<br>
[[attack the rat]](Rattack)
[[Rattack]]:
var jsRatCombatskill = get("RatCombatSkill");
var randomnumber = function rng(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
var jsCombatroll = randomnumber(1,6);
var jsCombatTotal = (jsCombatroll + jsRatCombatskill);
set ("Monsterhit", jsCombatTotal);
The rat atttacks with a roll of <b>{Monsterhit}</b>
Alex
10 Jul 2015, 13:02You're setting them as strings... set them as numbers instead
e.g.
e.g.
set ("RatHealth", 4);
Rockenden
10 Jul 2015, 14:21Argh! Cheers, Alex ![Smile :)](/phpbb-smilies/icon_smile.gif)
![Smile :)](/phpbb-smilies/icon_smile.gif)