LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

small project

I finally was able to open your code.   Here are some comments.

  • Since LabVIEW Projects (.lvprog) were introduced about a decade and a half ago, except for the most trivial LabVIEW code (such as a single isolated VI to test some concept), it is usually a good idea to start by chosing "Create New Project" (and giving your Project a meaningful name).  A reason to do so is that it creates a disk-and-programming structure to help organize LabVIEW code, especially useful (almost mandatory for preservation of sanity when the "project" gets more than a dozen VIs, TypeDefs, and other program constructs that "belong together".
  • I'm guessing you have a TypeDef that has the names of the States for your State Machine.  In the code, they show up as "ghost figures".
  • When using an Event Structure and dealing with a Value Change for a Control, it is much easier (both for you and for anyone reading your code) to deal directly with the Control (either by placing the Control, itself, inside the Value Change, or by using "NewVal") than by using a Control Reference and a property node to determine the underlying value.  
  • This is especially true when using Boolean Controls, which can have a "mechanical action".  The rectangular Buttons, for example, have, by default, a "Latch when Released" action.  When you place them inside their corresponding Value Change event, they will return to their default value after you read them (the wire leading from them has the "before" value for you to use).
  • Spending a little bit of time when wiring to keep the wires running mostly straight and horizontal will simplify your (and others) ability to see what is going on more clearly.  It also lets you "compact" your Block Diagram so it doesn't take up much space (at least 95% of all my VIs fit on a standard Laptop screen).
  • Neatness pays especially when debugging.
  • You've already (partly) learned that you should turn off Icon View on the Block Diagram.  I recommend going to "Tools", "Options", and on the Block Diagram window, unchecking "Place front panel terminals as icons".
  • Using a Numeric Control may be simpler (from a standpoint of User understanding and Code development) than trying to create a 10-button numeric entry array.  Note that the number is "entered" when you press the Enter button on the keyboard.  [I realize you might be trying to build not only a "dart game", but also a numeric keypad -- get the game and its logic going first, then worry about the "look and feel".]

Bob Schor

  • directly with the changing element, rather than with a reference to the element
Message 31 of 34
(482 Views)

Hi Bob,

Thank you very much for all your comments and directives to make it cleaner and readable. 

I am not tryingto make a dart game but a dart score app. I have to have a numeric pad for the player to enter their score, Also, I haven't used any arrays yet. I used numeric buttons. I don't know if you familiar with dart scoring goes.

There are 2 main games ( 501 and 301).

players1 starts with 501 points. Throws 3 darts and add up the total wich will be substact from 501 ( ie 501 - 45 = 456 ) that will be saved untill his turn again

Then he will start from 456 not 501 and totals his 3 darts count and goes on untill whoever  reach 0 first. I just gave the basic rundown as far as couting. the game is a little more complicated than that. Back to my problem is the fact that i cannot figure out the part where the substration happens and saving the score after every 3 darts. ( ie 501 - 45 -60 -22) untill his turn again. Try to run my vi untill you enter random score for player 1.You have to follow the notes in the ui

Thank you very much again

0 Kudos
Message 32 of 34
(474 Views)

@soccerfan wrote:

Hi Bob,

Thank you very much for all your comments and directives to make it cleaner and readable. 

I am not tryingto make a dart game but a dart score app. I have to have a numeric pad for the player to enter their score,

The score is a number (in fact, an integer).  If you make a Front Panel Control by dropping a "Numeric Control" from the Numeric Palette, it will put down a Floating Point Control (you can tell it is a Float because it is Orange on the Block Diagram).  Go to the Block Diagram, right-click the Control, choose "Properties", make it an I32 (32-bit Integer), and notice it turns dark Blue (guess what that means).  Now double-click the name ("Numeric") and make a "User-sensible name" such as "Score" or "Points" (or whatever is appropriate).  Let LabVIEW do the "hard work" of assembling single digits into a number for you.  You can type "123<backspace><backspace>45<enter>" to enter "145" (the two backspaces "erase" the previous 3 and 2 characters, and the <enter> "sets the numeric value" to "145").

Also, I haven't used any arrays yet. I used numeric buttons. I don't know if you familiar with dart scoring goes.

There are 2 main games ( 501 and 301).

players1 starts with 501 points. Throws 3 darts and add up the total wich will be substact from 501 ( ie 501 - 45 = 456 ) that will be saved untill his turn again

There are several ways to manage a "turn".  You throw three darts, one at a time.  This suggests you enter 3 scores, which (in turn) suggests a For Loop with 3 wired to "N".  Inside the Loop, you read one score (see above) and bring its value out of the loop in an "indexing tunnel" (which looks like an open square with a pair of brackets, "[ ]", inside it).  This creates an Array of the three Scores you just entered.

 

Now you can sum these three numbers (look in Array Palette for "Sum") and subtract it from the "Current Score" which is being held in a Shift Register (with 501, or whatever the starting Score is wired to the outside of the While Loop that controls the entire game).

 

I'm sure there are more rules to incorporate (for example, what if your current score is 25, and you throw 10, 15, and 20 -- if you need to use all three scores, you zoom past zero!  But you know the rules, so you can build them into your code (like have the game end and say "Ha, ha, you overshot, I win!!!".

Then he will start from 456 not 501 and totals his 3 darts count and goes on untill whoever  reach 0 first. I just gave the basic rundown as far as couting. the game is a little more complicated than that. Back to my problem is the fact that i cannot figure out the part where the substration happens and saving the score after every 3 darts. ( ie 501 - 45 -60 -22) untill his turn again. Try to run my vi untill you enter random score for player 1.You have to follow the notes in the ui

Thank you very much again


 

0 Kudos
Message 33 of 34
(429 Views)

Hello again,

 Floating Point Control (you can tell it is a Float because it is Orange on the Block Diagram

 

It doesn't show orange on my side. It's purple ( string controls)

 

You throw three darts, one at a time.  This suggests you enter 3 scores, which (in turn) suggests a For Loop with 3 wired to 

 

But you score the total of your 3 darts ( not one at the time) you can't move from the throw line untill you throw all the darts and then you walk to the score board and enter

your total . If your not good at math then you use the add button and total your 3 darts one at the time

'm sure there are more rules to incorporate (for example, what if your current score is 25, and you throw 10, 15, and 20 -- if you need to use all three scores, you zoom past zero!

It is called a "bust" and you come back to the previous score

I am aware of all the theory that you mentionned. However, i am stuck in the practicality  of things. I appreciate if you open my block diagram and show me were things went wrong (not the whole project but only the user input and substraction). There are a lot of work still to be done

Thank you for your tiime

 

0 Kudos
Message 34 of 34
(423 Views)