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

1024 - Why do list assignments work the way they do?

by - Joseph Ganci


Check out the CopyList(anylist) function description: ... When you assign a variable to a list, the variable contains only a reference to the list. If you assign the contents of that variable to another, only the reference to the list is copied.

The statement ListA:=ListB:=[] sets ListB as a referenced analog of ListA.

Yeah, I knew it was documented somewhere, and was perfectly meant to be that way, but it seemed perfectly logical to initialize list variables the way you initialize all other variables. I thought I would just warn you that this can lead to some unexpected results...


A word on why list assignments work this way. Aside from the fact that lists can be absolutely huge, being able to easily reference a list with another can be useful under certain conditions. For instance, if you set up a subroutine in Authorware (using Navigate call-and-return icons or perpetual conditional responses), you can have a placeholder list set up in the subroutine and "point" to it with the other. As an example, say you have a subroutine set up that will go through each location in a list and append to the end of each string the word "JOE":

repeat with i := 1 to listcount(tempList)
tempList[i] := tempList[i] ^ "JOE"
end repeat

This is an admittedly simple subroutine, but I'm keeping it simple here on purpose for illustration. Anytime you wish to append the word "JOE" to each location of *any* list now, you need only do the following:

tempList := myList

and then call the subroutine. Upon returning from the subroutine, myList will be correct. Later, you can do the same thing with another list:

tempList := yourList

After calling the subroutine, yourList will be correct. Neither yourList nor myList will affect the other.

In my classes, I like to illustrate list referencing with the following story:

A man and a woman get married and have a baby girl. Each decides on a name for the baby. The father wants to call the girl "Sonya" and the mother wants to call the girl "Mary" and neither will cave in to the other. The girl grows up being called Sonya by her father and Mary by her mother. When she turns 5, Sonya falls down outside and skins her knee. Does Mary also skin her knee? Of course, since they're the same person, just with two separate names. When you assign a list to another list, you are in essence giving another name to an existing list. If one list falls and hurts itself, so will the other.

By the way, I too was confused by this at first, but I have since found it a useful feature, and it is in keeping with some programming languages as well. I hope you will find it useful as well.


There are 0 reviews
Add your review
Back