01-04-2016 07:40 AM
Hi,
I am trying to create a game but my VI isn't working as I want it to. Im pretty much a beginner at labview and have no idea what is wrong with my code. Help Plz!!!
So far I have only added the 'up' and 'down' button, and I want the red square to stop at a black square, or otherwise follow the instruction of the button that is pressed.
Im not entirely sure how I should go about doing it. My try ended up in horrible failure.
Any help would be appreciated!
Thanks
Solved! Go to Solution.
01-04-2016 08:37 AM
How are you learning LabVIEW? Have you taken as many of the On-Line Tutorials as you can find? Have you looked at Example code, particularly code a good LabVIEW programmer has written to do something only slightly complicated?
LabVIEW responds very well to "Good Style" -- without it, the perjorative phrase "Spaghetti Code" takes on a whole new meaning. One of the best ways to prevent Code Sprawl is to encapsulate functions in sub-VI. Looking at your code, I see multiple loops that "do something", but I have no idea what this is. If each loop was a sub-VI that had a name (maybe "Move One Square Right") and an icon (maybe with a right-pointing arrow, or the words "Move 1 Right"), your main VI would be much simpler to comprehend, and to debug.
Bob Schor
01-04-2016 08:38 AM
It is not entirely clear at a quick glance exactly what you are trying to do. Have you drawn a flow chart or state diagram on paper describing exactly what the program should do?
I suspect that you have way too many loops. One or two is probably enough.
You have a lot of duplicated code or code which differs only by data values. That can probably be consolidated.
Terminals shoudl be inside the event case, especially for latch action booleans. You should also have a separate event case for the stop button.
Lynn
01-04-2016 08:40 AM
1. Stop using local variables. They are causing race conditions and you can be using data flow for every thing. The main thing is the have your "build map" loops pass data to your event loop. This includes initializing your shift registers..
2. Make an event for your stop button.
3. Put the controls in their corresponding events. This will allow the buttons to latch.
4. Work on having things line up better. It will help a ton keeping your paths easier to read.