At 04:53 PM 9/12/00, Paul Schulman wrote:
>Mark Boyd corrected some errors in my code (thanks, Mark) and I've fixed
>them but I still have problems. I am intending to fill out one list with
>the randomized properties of another list. I want to use an index value to
>get at the properties and values of the old list and place them in the new
>one but my code doesn't work. (I don't have the hang of the syntax yet).
One rule of thumb to keep in mind regarding syntax. Don't mix dot syntax
with the older syntax on the same line as you've done with:
>RandomDistanceList.addProp(getAt(oldDistanceList, aDistance))
The above line fails because there is no property to add, just a point
value. You'll need to extract the property name from the old list with the
getPropAt() function.
Notice also that your list has only 5 items, yet your repeat loops through
6 iterations. This will fail when the list has been emptied in the 5th
iteration. I've set the repeat to loop indefinitely (OK, infinitely), but
there is a test for the list count that will exit the loop cleanly.
I often find it easier to break out the elements of a long line of code and
watch things in the debug window.
on test
oldDistanceList = [#veryNear:point(20,20),
#near:point(70,70),#middle:point(120,120),#far:point(170,170),#veryFar:point(220,220)]
RandomDistanceList = [:]
repeat while true
if oldDistanceList.count < 1 then exit repeat
aDistance = random(count(oldDistanceList))
theValue = oldDistanceList[aDistance]
theProp = oldDistanceList.getPropAt(aDistance)
RandomDistanceList.addProp(theProp, theValue)
oldDistanceList.deleteAt(aDistance)
end repeat
return RandomDistanceList
end
-- Welcome to Director --
put test()
-- [#veryFar: point(220, 220), #veryNear: point(20, 20), #near: point(70,
70), #middle: point(120, 120), #far: point(170, 170)]
After things are debugged, you can always combine them back into a single
line if you like.
RandomDistanceList.addProp(oldDistanceList.getPropAt(aDistance),
oldDistanceList[aDistance])
Just one more hint. When posting Lingo to the list, it's often hard enough
to deal with the line breaks imposed by the email software. Placing double
and triple commented lines makes it hard to see the actual Lingo in the
email. Not a biggy, just thought I'd mention it.
HTH
--
Mark A. Boyd
Keep-On-Learnin' :)
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]