Think of something that you wish Authorware could do but it doesn't? Let the our good friends at Macromedia know via the wishlist. Please let us know if you find any of the materials on this site inappropriate or offensive. Please include the url and why the material should be reviewed. Comments and questions about the site are also welcome. Please no Authorware questions, use the AWARE list. |
Back
B5006 - How can I set up a jump menu from a text file? by - Joseph Ganci
You're making
it a bit harder than it has to be. First, a word of caution: GetVariable
and all the other variables that are contained in the Target category
are meant to be used in Knowledge Object building, meaning they are only useful
in source code and won't work at runtime. They have no need to - a Knowledge
Object's work is done in source, not at runtime. However, this is not a problem
as you don't need the function. By the way, if
you found the variable in the All category, then you can tell which category
the variable is in by looking right about the category pulldown menu. It'll
tell you there. Also, the method
you're using wouldn't work regardless (don't despair - we all start somewhere!).
Reading in a text file doesn't assign variables from that text file automatically
or by using the GetVariable function. It actually would take a lot
more work than that. But, good news, we don't have to! Basically, you don't
need to do all of the conversion that you're doing. I would start by eliminating
the actual variable names from the text file (I called it "options.txt").
Make it so that it looks like this: Option 1 OK, so you see
what I've done up above. I've placed all the menu options in a row, then the
file names for each corresponding option in the same order. This is a bit
hardcoded right now, since it assumes exactly 4 options. Hang on, and I'll
show you in a bit how to make it a little more generic. Here's what
the code will look like: Your code for
reading in the file would look like this: file := ReadExtFile("options.txt") So as you can
see, the variable file will obtain the whole contents of the text
file, the variable options gets a copy of the first four lines, and
the variable jumps gets a copy of the last four lines (lines 5 through
8). I show the options on the screen as a menu, and set up an interaction
icon with a hot spot over the menu. If the user clicks inside the hot spot,
a calculation icon is executed as feedback with the following: file := GetLine(jumps,
LineClicked) And that is it!
Now, for the streamlining part. If you wanted to create the code above so
that it worked no matter how many options, the only thing that would change
is the initial calculation: file := ReadExtFile("options.txt") Here's what's
happening now. The numoptions variable is set to the number of lines
in the text file divided by 2, which is the number of options we have. The
options and jumps variables are then set according to the
numoptions. If there are 3 lines, options will be set to
the first three lines of the text file and jumps will be set to the
last three, and so on. Add your review Back |