This page looks best with JavaScript enabled

Training501: the function for a training leg

 ·  🕘 2 min read  ·  🤖 Matteo Miotto

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:

  • player: player namee
  • save: if training leg must be stored in a text file. T by default
  • file: (optional). Name of the file in which to save the training. By default it is NA, if save = T and file = NA, a prompt will ask you to select the destination file
  • For later use, it is strongly recommended to run the command saving the result in a variable:
    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:

    1. 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
    2. Check that the player has not busted
    3. Subtract the value from the player's score and move on to the next visit
    4. (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:

  • First line: leg id, player name
  • Second row: darts thrown, in the form 18, t19, d20, ...
  • 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).

    Share on
    Support the author with

    Matteo Miotto
    WRITTEN BY
    Matteo Miotto
    Genomic Data Science master student

    What's on this Page