LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scoring Table for Dart Game

Hi everyone,

 

I have made a dart game by using a program from one of the posts in this forum...I made the mouse to move randomly in the scoreboard and made it multiplayer, each player has a number of tries. When each player presses the button down of the mouse, the score is displayed in an indicator...I want to display all the scores of each player in a table like this:

 

puntajes.PNG

And if possible, I would like to display the name of the winner.!

Any help will be appreciated

 

Thanks in advance

 

 

Download All
0 Kudos
Message 1 of 9
(4,842 Views)

With any experience using LabVIEW, you should be able to code this up in 15 minutes.  If you lack this experience, take advantage of the numerous LabVIEW Tutorial material, some of which is listed in the upper right corner of the Forum's main page.

 

Bob Schor

0 Kudos
Message 2 of 9
(4,832 Views)
I have seen the tutorials but I Did not find information about What I want to do. That is Why I am asking in the forum.
0 Kudos
Message 3 of 9
(4,804 Views)

At the bottom of your VI I see you made a While loop to try and do this.  The problem is the way that you have written it it only runs once.

 

3 things:

 

It should probably be a "For" loop, using the "number of turns for each player" input as its loop count

It should probably be in your big main While loop and not at the bottom by itself

It probably shouldn't have a delay timer inside it

0 Kudos
Message 4 of 9
(4,793 Views)

Hi, Kyle97330

 

I followed your suggestion, but it is not working. Every time I click the button down of the mouse, the table is filled with only two identical rows and if I click again, these rows are deleted and replaced with other two identical but with different scores. I have attached the program.

 

 

0 Kudos
Message 5 of 9
(4,750 Views)

2 more problems I see:

 

You don't wire anything to the "insert array" indexes, so it always tries to add to 0,0

You're passing in the same "score" variable each time.  It should probably be a score array.  Find where the score is recorded and have it add to an array instead of only putting out the score for that turn.

 

0 Kudos
Message 6 of 9
(4,726 Views)

Hi 

I have been working on my problem. I tried to make and array of the scores using a shift register and the insert into array function, but it is not displaying anything nither on the table nor in the indicator of the output array. I do not know what is wrong. 

 

Please help.

0 Kudos
Message 7 of 9
(4,676 Views)

Hello TWRLK good afternoon,

 

Thanks a lot for contacting the forum support, after checking the code I have attached an example of the code to generate the table based on your code. I have to mention the most probable scenario is that the application will not behave correctly since you have 2 loops running at the same time and this can create a race condition (random position of the cursor). My recommendation is that you can use a producer/consumer event driven pattern (File > New > Producer/Consumer Design Pattern), so that any of the clicks the user make can be stored into a queue and the data would not be lost for each and every turn. (In the producer loop you can have the random position and generation of the points based on the position of the cursor en-queued and the consumer loop will de-queue the elements and have the control of the points and generation of the table).

 

I hope that this information is helpful,

 

Best regards,

 

 

CaEnOs

0 Kudos
Message 8 of 9
(4,472 Views)

Dear TWRLK (I won't try to pronounce that!),

 

     It looks to me like you may have fallen into a LabVIEW "Trap" (I've done it, myself, so don't worry ...), namely it is so easy to build pretty and clever User Interfaces that we forget that we have to "do something" with it.  Starting with the GUI and tacking on some "code to make it work" usually results in a bit of a mess, so let's reverse things and ask "What Do I Want to Do", and worry later about "How Do I Do That?".

 

     I'm going to base this on the problem that you initially posted, namely setting up a Scoring Table for your Dart Game.  You show a picture of what appears to be a Table Control/Indicator, so I'm going to assume that this is how you would like your Scores to be displayed.

 

     Let's start by asking what the Columns and Rows of the table represent.  Well, the Columns seem to be the Players, with perhaps the Name of each Player written as a Column Header, and the Rows seem to be the scores for each Round, with perhaps the Round number written as a Row Header.

 

     So before you even start playing your game (i.e. "throwing darts"), you first need to get a list of Players.  This will do two things for you -- determine how many "Dart Throws" you'll need to make in a Round (since every player needs to have a turn throwing) and will provide the information you will need for the Table's Column Headers.

 

     Now you are ready to Play a Round.  Each Player (and you know how many, and even their names!) takes their turn and receives a score for that round.  The Score is an Integer, and if N Players play M Rounds, this suggests that the scores should be held in an M by N Integer Array.  

 

     At some point, you will finish playing M Rounds, and will want to announce the Winner. Having the Scores in a 2D Integer Array will facilitate this computation.

 

     If you've been paying attention to this Forum, or have spent enough time and/or had a good LabVIEW Instructor, you might recognize that carrying out a series of steps such as "Get List of Players", "Play One Round", "Throw One Dart", "One Player Turn", "Calculate Score" describes something called a State Machine.

 

     But we're not really going to focus on the State Machine at the moment -- instead, let's consider creating and updating your Scoring Table.

 

     What do you know about LabVIEW Tables?  I presume you know that they are an arrangement of cells holding Strings, so their content can be considered a 2-D Array of Strings.  Do you know that Tables, in addition to the String Data that appears in them, also have separate Row Headers and Column Headers?  Here's a picture of a Scoreboard after two rounds between Bob, Carol, Ted, and Alice,  You can see Alice is winning ...

Dart Scoreboard.pngDart Scoreboard Code.png

 

     Let's go back to the State Machine and think when we'd do what with this Table.  We start with "Get List of Players", which gives us N, the number of Columns, and the names of the Players (which, if we're clever, we can insert into the Table as Column Headers).  Now we are ready to Play One Round.

 

     One of the first things we might want to do (but we can do it later, of course), is to add "Round xx" as a Row Header for our Table.  We might then execute the One Player Turn State N times (once per player), keeping track of which player (Shift Registers are good for this) and adding an entry to our Score Array after the player finishes his/her turn.  When all the players have finished their turn, we can run the piece of code shown above to update the Scoring Table for that round.  [We could also update it as each player throws a dart, if we want ...].

 

     At some point, we reach the "Finish the Game" criterion (it might be after 10 rounds, or when someone scores more than 100 points -- it's up to you).  That is when you go to the Calculate Score state.

 

     So here's my final Piece of Advice.  If you don't (yet) know about State Machines, do the following:

  1. Start LabVIEW.
  2. Choose Create Project.
  3. in the right-hand pane, choose Simple State Machine.
  4. Complete the setup, save the Project, then study it.  Start with the Documentation (pretty thorough), then look at the code, itself.
  5. Now comes the Hardest Part -- start your Project all over, basing it on this State Machine Design.  Keep almost nothing of your old code.  Make use of Shift Registers to store the data for the State Machine.  This should include the Array of Player Names and the 2D Score Array.  This may seem too painful to contemplate, but I think you will find that your formerly-complex Project has now been broken down into several much more simple steps.

     One final word of advice -- sub-VIs are Good for You!  Notice the size of the State Machine you just created -- it easily fits on a Computer Screen.  You shouldn't need to enlarge it at all -- if you find yourself "needing more room", ask "What details can I hide inside a sub-VI so that I can concentrate on the Main Point here?".  As an example, the code needed to ask the User "Enter the name of Player 1" and build the Player Array can be put in a sub-VI -- you need to pass into this sub-VI the number of players (such as 4, which you get in the Initialize State) and its output should be the array of Player Names ("Bob", "Carol", "Ted", "Alice").

 

Bob Schor

 

 

0 Kudos
Message 9 of 9
(4,442 Views)