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.


B5006 - How can I set up a jump menu from a text file?

by - Joseph Ganci

I have made an Authorware 5 piece that is to read in a simple text file and create a menu based on the information contained in that text file. The code below evaluates which line the user clicked and launches the appropriate file. It works perfectly when I am in authoring mode, but if I package the piece (either to .a5r or .exe) this code ceases to work--the variable gofile" is zero when run. Any ideas? I've been staring at this for a week now and cannot understand why it would change in the packaged piece. I'd appreciate any help.

st_LastLineClicked := String(LastLineClicked)    -- convert line choice to a string
filenamed := "Runner1"^st_LastLineClicked        -- build filename based on line clicked
gofile := GetVariable(filenamed)                               -- assign value of built string to gofile

The sample text file would contain the entries:

Choice11 := "Option 1"
Runner11 := "option.exe"
Choice12 := "Option 2"
Runner12 := "Whatever.exe"

and so on. Essentially, the user sees a list of all variables named ChoiceXX, when a line is chosen I figure out which line was selected and get the corresponding executable filename to launch. Like I said, this works in authoring mode but not when packaged. When this piece of code is run in a packaged piece you get a file window that asks "Where is file 0.EXE?" In authoring mode it opens the corresponding file. Can you shed any light on this problem? Let me know. Thanks.

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
Option 2
Option 3
Option 4
option 1.exe
option 2.exe
option 3.exe
option 4.exe

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")
options := GetLine(file, 1, 4)
jumps := GetLine(file, 5, 8)

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")
numoptions := LineCount(file) / 2
options := GetLine(file, 1, numoptions)
jumps := GetLine(file, numoptions + 1, numoptions * 2)

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.

There are 0 reviews
Add your review