Example Code

Example Code - Word Hunt

Code and Documents

Attachment


Summary:

Word Hunt is a simple word puzzle - find out what the target word is by typing words in and using the feedback to close in on the word.

Each word is either higher or lower than another word, based on the simplest dictionary concept, so anyone with a computer science background should immediately get an idea in their head (and in case you're wondering, the dictionary included with the code has ~8500 words).

Function:

Type in a word and press Enter. One of four things will happen:

  1. The word is correct. It will be colored green and you will get a new word.
  2. The word isn't in the dictionary. It will be colored red.
  3. The word is "lower" than the target word, so it will go up.
  4. The word is "higher" than the target word, so it will go down.

The code demonstrates some UI effects, as well as basic use of XControls.

Steps to execute code:

  1. Unzip the files.
  2. Open the project file.
  3. Open the VI and run it.

Screenshots:

Word Hunt.png

<object id="scPlayer" width="278" height="573" type="application/x-shockwave-flash" data="http://content.screencast.com/users/YairN/folders/Default/media/88b9028e-3fa8-42ee-8fec-8d3094bc68e1..." >  <param name="movie" value="http://content.screencast.com/users/YairN/folders/Default/media/88b9028e-3fa8-42ee-8fec-8d3094bc68e1..." />  <param name="quality" value="high" />  <param name="bgcolor" value="#FFFFFF" />  <param name="flashVars" value="thumb=http://content.screencast.com/users/YairN/folders/Default/media/88b9028e-3fa8-42ee-8fec-8d3094bc68e1..." />  <param name="allowFullScreen" value="true" />  <param name="scale" value="showall" />  <param name="allowScriptAccess" value="always" />  <param name="base" value="http://content.screencast.com/users/YairN/folders/Default/media/88b9028e-3fa8-42ee-8fec-8d3094bc68e1..." />  Unable to display content. Adobe Flash is required. </object>

VI Snippet:

Not applicable.

VI attached below


___________________
Try to take over the world!

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
wirebirdlabs
Member
Member
on

Your "Blink" method is a good candidate for overrideable base properties of an XControl. I'm not the biggest fan of placing method parameters in state data, then handling the method code inside the Display State Change case, but this is a limitation of passing data into the Facade VI, not Yair's design. (While not evident in this example, the flaw here is that state data gets unnecessarily bulky as more and more methods are introduced) A better "hack" involves placing hidden control on the FP, then using the Val(Sgnl) to pass data into the XControl (the challenge here becomes properly handling the ref to that control through encapsulation, ensuring it can be easily traced)  Five stars for simplicity and effectiveness.

tst
Knight of NI Knight of NI
Knight of NI
on

JackDunaway wrote:


                       

A better "hack" involves placing hidden control on the FP, then using the Val(Sgnl) to pass data into the XControl

...

Five stars for simplicity and effectiveness.                  

I have to admit that this design was mainly used because of the time factor. This was my second example and I didn't have time to work on it, so at least the last three words in your comment are correct.

I'm not sure what I would do for something like this with a full XControl, but I would probably use a queue of objects which would allow me to encapsulate the data in a lossless manner, and then shove the info into the state cluster inside the Facade VI (assuming it was needed there).


___________________
Try to take over the world!
Contributors