Zlatoun Posted April 11, 2023 Report Share Posted April 11, 2023 Hi, I would like to create a project but I am new to Labview. I would like to simulate a penalty shootout where a user chooses a direction to shoot (center, right, or left) and an opposing goalkeeper simulated by a random number generator (ranging from 1 to 3) determines where the goalkeeper dives and if they dive on the same side as the shot, they stop it. When they stop a shot their score increases by 1, but if they don't stop it, the player's score increases by 1 and the game ends when one of the two reaches 5 (with a while loop). The score is displayed in a table with multiple rows and the score's progress is visible through a graph. Could someone give me some advice on how to do this? Quote Link to comment
Antoine Chalons Posted April 12, 2023 Report Share Posted April 12, 2023 it's ok to cross-post, just notify when you do https://forums.ni.com/t5/Discussions-au-sujet-de-NI/Aide-projet/m-p/4297462#M35675 This sounds like homework, am I right? Have you started at all to create some code? My suggestion is you try your best effort to create something as basic as it may be and if you're stuck, post your code (the VI files in a zip) and then we have a base to start helping you. I'll give you a head start, here's a VI that will generate a random number ranging from 1 to 3. Quote Link to comment
Zlatoun Posted April 12, 2023 Author Report Share Posted April 12, 2023 Hello, I have indeed started coding. So far, I have tried to create the part where the player chooses to shoot either in the center, right, or left. I associate each direction with a number from 1 to 3 using a switch-case structure, and then compare it to the random number generator. If they are equal, the goalkeeper's score increases by 1, and if they are different, the player wins 1 point. For this, I use a shift register to initialize both scores, and then use two cases for the increment of either score. My problem for now is that both scores increase at the same time, the player's score starts at 1 instead of 0, and another minor issue is that the LED indicating if the goalkeeper stops the shot never turns on. How could I improve and correct these errors? Quote Link to comment
Antoine Chalons Posted April 12, 2023 Report Share Posted April 12, 2023 you have to keep track of the score for the goal-keeper and the score for the player independently, so one shift register for each, both shift registers initailized with 0 the while loop is running without any timing control, therefore 'as fast as possible, you'll see this if you create an indicator of the the iteration terminal (the blue square 'i' at the bottom left) of the loop that's why you never actually see the 'stop' turning on, it goes so fast that you don't see it, if you simply add a 1 second wait timer in the loop you'd see it. But there are better ways to do the 'processsing' of who gets a point only when you clic on the 'shot' button, take a look at the event structure. Quote Link to comment
Palanivel Thiruvenkadam Posted April 12, 2023 Report Share Posted April 12, 2023 Though it seems to be homework program, I have Modified your code to support your requirement. Please do go through the code and understand, don't just use and complete your task,if it resolves your issue. ShootingGame.vi Quote Link to comment
Zlatoun Posted April 12, 2023 Author Report Share Posted April 12, 2023 Thank you, you have helped me greatly. I have taken what you have done and redone it myself to understand it. I changed the while loop stop condition so that the match stops when one of the two has reached 10 points. Now I would like to store the scores in a graph and a table that update in real time. For the graph everything works as expected but I can't link the table. Do you have an idea how to make it works. I would also like to put a message that says if the goalkeeper or the player, should I use a case structure and put it at the output of the event structure? Quote Link to comment
Zlatoun Posted April 12, 2023 Author Report Share Posted April 12, 2023 Here's my project's link. Projet V2.vi Quote Link to comment
Palanivel Thiruvenkadam Posted April 12, 2023 Report Share Posted April 12, 2023 32 minutes ago, Zlatoun said: Thank you, you have helped me greatly. I have taken what you have done and redone it myself to understand it. I changed the while loop stop condition so that the match stops when one of the two has reached 10 points. Now I would like to store the scores in a graph and a table that update in real time. For the graph everything works as expected but I can't link the table. Do you have an idea how to make it works. I would also like to put a message that says if the goalkeeper or the player, should I use a case structure and put it at the output of the event structure? If you wanted to append running data to table, just use Property Node (value) for Table (Read Existing Table Value and Append the run time value). For Message use Case Selector and update Goal Keeper/Player inputs. Quote Link to comment
Zlatoun Posted April 12, 2023 Author Report Share Posted April 12, 2023 Thank you, the project is now functional. My last problem is that I don't understand how to display "player wins" or "goalkeeper wins" in the "who wins?" string indicator. Quote Link to comment
Palanivel Thiruvenkadam Posted April 12, 2023 Report Share Posted April 12, 2023 You want to display once it reaches 10 or or every shoot you need to display? Quote Link to comment
Zlatoun Posted April 12, 2023 Author Report Share Posted April 12, 2023 I would like to display once it reaches 10 for the player or the goalkeeper. Quote Link to comment
Palanivel Thiruvenkadam Posted April 12, 2023 Report Share Posted April 12, 2023 3 minutes ago, Zlatoun said: I would like to display once it reaches 10 for the player or the goalkeeper. Use Boolean Array to Number Function, where you will get 0 if nothing is true and 1 if first element of array is true and 2 if second element of array is True and 3 if all two elements are true. Use case structure and based on 1/2 display Message. Quote Link to comment
Zlatoun Posted April 12, 2023 Author Report Share Posted April 12, 2023 OK thank you very much! Your really helped me a lot for with my project. Quote Link to comment
Palanivel Thiruvenkadam Posted April 12, 2023 Report Share Posted April 12, 2023 Just few Tips on your Coding, 1. Indicator of Goal Keeper Score and Player Score should be of Same data as you Init (Int) 1. 2. Make sure you Avoid Wire Bends in all possible places. 3. Label for all Constant Values. 4. Your Code should be readable and scalable for future updates. Quote Link to comment
Lipko Posted April 13, 2023 Report Share Posted April 13, 2023 The result of one "Select" should be the false input of the other "Select". The order should not matter. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.