## Accumulate Score on a random number.

Hello.

I need help. How can I get the score to accumulate on a random number?

Here is the code below:

[[start]]:
@set p1_score = 0

``````getRndInteger = function(min,max){
return Math.floor(Math.random()*max)+min;
};
``````

Hello.

get a random integer

var rndInt = getRndInteger(0,2);
set("int",rndInt);

Player 1's Score: {p1_score}
{RESULT}

get a random integer

[[RESULT]]:
{if int=0: {RES00} }
{if int=1: {RES01} }

[[RES00]]:
You missed the shot.

[[RES01]]:
@inc p1_score 2

K.V.

Something like this?

``````[[start]]:
getRndInteger = function(min,max){
return Math.floor(Math.random()*max)+min;
};
@set p1_score=0

Hello.

[get a random integer]

Player 1's Score: {p1_score}

[get a random integer]:
var rndInt = getRndInteger(0,2);
set("int",rndInt);

{if int=0: {RES00} }
{if int=1: {RES01} }

[[RES00]]:
You missed the shot.

[[RES01]]:
{@p1_score+=2}

Player 1's Score: {p1_score}
``````

This will work out just fine. Thanks!!

K.V.

This topic is now closed. Topics are closed after 60 days of inactivity.

Quest
Squiffy
ActiveLit

Documentation
Blog
GitHub

Forums