LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

memory game vi

Solved!
Go to solution

@A.A.A. wrote:

Tim, your program works and does the job but it differs insome situations from my program. You use 4 independent variables while I use an array; you also use an event structure.

Is there a way to eliminate the event structure and use simple loops and case structures(I have minimal knowledge with the event structure)

Can you show me an example where the user clicks on different elements of the OK array and the outcome is the index of this array; if I understand that part I will do my own version of the mind game with no event structure

Thats what I did for this part and it doesnt work userindex.png


 

You use 4 independent variables while I use an array; you also use an event structure.Is there a way to eliminate the event structure and use simple loops and case structures (I have minimal knowledge with the event structure).

 

If you look at whit I did I do not use four independent variables except for the display. I am using an array of four then adding that to a 2D array of Boolean values. This is so I can keep the history of what has been played so that we can play it back and check to see if the operator was correct. You can do it your way too but you will still have to put your values into an array and keep up with what button was pushed. The event structure is easy to use. If you want to go down the path of no event structure good luck to you and I wish you well.

 

Can you show me an example where the user clicks on different elements of the OK array and the outcome is the index of this array; if I understand that part I will do my own version of the mind game with no event structure

Thats what I did for this part and it doesnt work

 

I did enough for you to see major concepts I am not going to redo what I have do to try to do it your way. As you said mine works and yours does not. If you want to do it your way you need to figure that out on your own. I definitely gave you enough to see how it should be done.

Tim
GHSP
0 Kudos
Message 11 of 25
(1,189 Views)

@A.A.A. wrote:

Can you show me an example where the user clicks on different elements of the OK array and the outcome is the index of this array; if


Event structure is the way to go. They are ideal for when you are waiting for a user to click on something. The program just sit there waiting. Now YOU will have to write code that polls the array looking for a click and also write code for when nothing happens.

 

But is you insist..

Arrays of Boolean you can't set the Mechanical Action to one of the latched modes so YOU are going to have to write extra code to reset the arrays after they click.

A cluster you can set the Mechanical Action.

A -1 means the the user did not click anything (YOU need code to handle that)

memory game.png

Omar
0 Kudos
Message 12 of 25
(1,186 Views)

Omar, thanks. I'll try to make my code.

Tim, thanks for the help! Don't get me wrong! I'll try to do it without the event structure.

0 Kudos
Message 13 of 25
(1,179 Views)

Yup, takes tooooo much programing for each case 😕

I'm going to learn more about the event structure.

0 Kudos
Message 14 of 25
(1,169 Views)

@altenbach wrote:

Maybe you should start with explaining what the program is supposed to do. Is the final goal something like simon


We ask again just what it is the overall program is suppused to do?

How will it work from the view of the user? How will the user "play" the memory game?

Omar
0 Kudos
Message 15 of 25
(1,167 Views)

Ok,

The user uses a numeric control to limit how many LEDs will light randomly (example if x=4 then 4 LEDs will turn on randomly 0-3-1-0.. and on the other array the user will try to mimic the turn of the LEDs by clicking on the appropriate x index at the OK elements. [ I tried on the first couple of codes to compare the indexes but I found difficulty on getting the indexes done by the user)

The program repeats until three mistakes by the user. 🙂

There is also a numeric control to define the difference between the turning on of the LEDs.

 

Are you sure the event structure is the only way to solve such a game?

 

 EDIT:

There is a button for PLAY! and a indicator showing the numbers of mistakes

0 Kudos
Message 16 of 25
(1,163 Views)

Are you sure the event structure is the only way to solve such a game?


No, it is just one of the ways

 

The real solution involves a state machine.

 

State 0: Setup or reset game

State 1: Wait for Play button to start next game or Exit button to quit the game.

State 2: Get random number of LEDs to turn on and place in I32 array (use a shift register for this).

State 3: Play back or display the array to the user.

State 4: Read user clicks on the array and check it against I32 array

                If user misses jump to BIG RED SCREEN state.

                If user gets through the complete array jump to Reward state.

State 5: BIG RED SCREEN of death state (provide mild electrical shook) then jump to reset game

State 6: Reward State Give cookie then  Jump to reset game   

 

Use shift registers.

Use enum Type Def for your states

 

Post something back,  we’re not going to completely solve your assignment for you, but we will point you in the right direction.

Omar
Message 17 of 25
(1,154 Views)

@A.A.A. wrote:

Ok,

The user uses a numeric control to limit how many LEDs will light randomly (example if x=4 then 4 LEDs will turn on randomly 0-3-1-0.. and on the other array the user will try to mimic the turn of the LEDs by clicking on the appropriate x index at the OK elements. [ I tried on the first couple of codes to compare the indexes but I found difficulty on getting the indexes done by the user)

The program repeats until three mistakes by the user. 🙂

There is also a numeric control to define the difference between the turning on of the LEDs.

 

Are you sure the event structure is the only way to solve such a game?

 

 EDIT:

There is a button for PLAY! and a indicator showing the numbers of mistakes


The event structure is not the only way just the easiest and most efficient

Tim
GHSP
0 Kudos
Message 18 of 25
(1,151 Views)

http://forums.ni.com/t5/LabVIEW/How-can-I-stop-the-inner-while-loop-when-the-outer-while-loop/td-p/1...

Now that I'm dont through my finals, I want to learn about state machine.

Unfortunately, the labs are closed and I can't use the DAQ and NiElvis to test the project; so I have decided to learn state machines by my old post about memory game.

i have done a code but I faced some difficulties:

I'm not sure if I'm using the enum constant the right way. In the help, it stated that it does not take it as an integer.

The state click; I am not sure about the logic; also is there a better way?

other than that, give me advices to fill the gaps.

Thank you for your patience.

Best

 

P.s.

I saved two files/I am not sure why I am uploading StandardStateMachine1...

Download All
0 Kudos
Message 19 of 25
(1,119 Views)

1.  Your control needs to have all the states defined in the enum.

 

2. All of your constants need to use the typedef'd version.

 

You have a lot of rogue enum constants scattered through out that aren't tied to the typedef and have only one state defined.  And each instance of those defines a different state, all at value 0.  Your case structure has multiple states, but the only ones that are valid are the ones that exist in the typedef.  The case structure is essentially tied to the typedef, and the states that are declared through those rogue constants are defined in the typedef.  Thus those states are undefined in the case structure.

 

1.  Define all states in your typedef control.

2.  Replace all of your enum constants with a constant derived from the typedef control.

 

Now if you ever need to add another state, add it to the control file and all constants will be updated automatically.

 

 

Also, you need to modify your LED booleans to be switch action rather than latch action in order not to have errors using the local variables.

0 Kudos
Message 20 of 25
(1,114 Views)