02-11-2022 02:07 PM
Hi all,
I'm learning LabVIEW for a coop position, so I'm fairly new to it. I am practicing using the JKI State Machine by creating a game of Hangman. For those who don't know what Hangman is, a player tries to guess letters of a word, each incorrect guess brings you closer to losing the game (6 wrong guesses).
I had made the front panel so that the player would not have to type their letter guess, instead they would just click a button and submit their guess. I have every letter of the alphabet stored in a cluster, whenever the player clicks a button in the cluster it becomes their 'current guess', they can then submit their guess.
The challenge I've come across is that I'm using an event case for every letter in the cluster, hence my event case list is very long. There must be a better solution to this rather than the brute force I'm currently using. Any thoughts?
Thanks in advance for the help!
Tristan
Solved! Go to Solution.
02-11-2022 02:15 PM
Use a single event case for all letters; namely the Value Change event on the cluster.
In that event case wire the "New Val" and "Old Val" to the inputs of an Not Equal comparison. Then to a Cluster to Array function, then search the array for TRUE. The index coming out will be the index of the clicked button in the cluster.
02-11-2022 02:21 PM - edited 02-11-2022 02:22 PM
Hi trlee,
check the whole cluster for a ValueChange event:
Then convert the resulting cluster into an array and search for a TRUE in the boolean array…
Edit: Paul was faster than me, and shows the same using an English LabVIEW version…
02-11-2022 02:21 PM
Thanks for the quick response! I'll go try that out right now.
02-11-2022 04:32 PM
FYI, you can select more than one solution if you feel that more than one post solved the issue.
02-11-2022 06:15 PM
Since you already labelled all the buttons by their letter, expanding Paul's and Gerd's solution is simple, see below