Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How to make a Win/Loss Ratio/Stat??

Asked by 10 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

I am making a game kinda like deathrun, and I need a script that can use the wins and loses and make them a W/L Ratio?? Can anyone help? And I need the whole thing to save to. How could I use DataPersitance for it??

1 answer

Log in to vote
0
Answered by
Dom2d2 35
10 years ago

I can help you with the basic math for this problem. So, you have wins, and losses. Let's say that the player has won 5 times, and lost 20 times. We can find the ratio by dividing 5 by 20. This gives us 0.25, which is the ratio. So the code would look something like this:

WinLossRatio = wins / losses

Now, we are still presented with an issue, for example, let's say a player has lost 7 times and won 2 times. If we do the math for this issue, it comes up with 0.28571428571, that is a bit long. In this case, we will need to round the number.

function round(WinLossRatio, 2)    --First argument is the number, so we'd put WinLossRatio. The second argument is decimal, so we'd put it what decimal place we want the number rounded to. 
 decimal=decimal or 0
 local mult=10^decimal
 return math.floor(number*mult+.5)/mult
end
Ad

Answer this question