> My loop changes the location and color 5 times for
> each mouse click and I want one mouse click, one change.
Don't confuse a repeat loop with something you want to happen repeatedly a
fixed number of times (what?!). <-- I probably could've worded that better.
Anyway, you're cycling thru all 5 iterations on each mouseDown. Instead of
that, keep a counter variable and increment it on each mouseDown. This may
also require you to build your randomDistanceList only when the counter = 1.
Remove all this from a repeat loop structure, and do it once per mouseDown.
repeat with i= 1 to randomDistanceList.count
r = random(4)
[ snip ]
updateStage
end repeat
And not that you asked, but here are a couple of syntax variations on your
script. Read them if you want to; your code does the same thing.
1) Making a list of your random possibilities, & then choosing a random
element from it, often takes less typing than using if statements. Example:
x = [ 1,-1 ][ random(2) ]
y = [ 1,-1 ][ random(2) ]
Does the same thing as:
if random(2) = 2 then
x = 1
else
x = -1
end if
if random (2) = 2 then
y= 1
else
y = -1
end if
In this case, you can accomplish in 2 lines what took 10 before.
2) Case statements are usually easier to read and maintain than nested-if
statements. Example:
case r of
1: sprite(1).color = rgb( 0,0,255 )
2: sprite(1).color = rgb( 0,255,0 )
3: sprite(1).color = rgb( 255,255,0 )
4: sprite(1).color = rgb( 255,0,0 )
end case
Does the same thing as:
if r = 4 then
sprite(1).forecolor = rgb(255, 0, 0)
else if r = 3 then
sprite(1).color = rgb (255, 255, 0)
else if r = 2 then
sprite(1).color = rgb (0, 255, 0)
else
sprite(1).color = rgb(0, 0, 255)
end if
3) Bracket list syntax frees you from using the horrid getAt() syntax.
Example:
randomDistanceList[ i ]
Does the same thing as:
randomDistanceList.getAt(i)
Take them for what they're worth,
Rob
/*********************************
* Rob Wingate, Software Human *
* http://www.vingage.com *
* mailto:[EMAIL PROTECTED] *
*********************************/
[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!]