Today we see the training501 function, which allows us to perform training legs at the classic 501 darts game.
Function launch and input
Let's start with the launch of the function and the necessary inputs. The function will be launched with the command training501(input)
and it will have the following inputs:
var <- training501(input)
Instructions and darts scores values entry
The way of entering values is the same as that used for the function match_501.
Once the values have been entered, the function will perform the following operations:
- Check that the entered values are valid (right shape and existing numbers). Otherwise, an error message will be issued and the player will be prompted to re-enter the values of the three darts
- Check that the player has not busted
- Subtract the value from the player's score and move on to the next visit
- (In closing) Check that 0 has been reached with a double
End of the training
Once the training is finished, an object of class legtr will be returned. If the object has been saved in a variable, it will only show that the training is over, otherwise a message will be shown that presents the date, the player’s name and the number of darts used to close.
File saving
If you decide to save the workout to a file, the function will add 2 lines of text to that file. In details:
Get info on training leg
To get information about the leg, you can use some of the get functions described in this post (getPlayers, getID, getDate).