I am encountering what to me seems strange behaviour within a repeat loop.
In the following script, put theta into fld "theta" does not result on display of theta until the script has exited the repeat loop. Even stranger, moving the line "put phi into fld "phi"" above "end repeat" seems to result in the script hanging. I don't see any reason why using a PUT command within a repeat loop should be illegal. What I would have expected is that the value of theta would have been updated each time the script loops through the outer repeat loop and that a similar result would have been obtained if the line "put phi into fld "phi"". Am i missing something important?
on mouseUp
global p, d, sumx, sumz, ax, az, Ao
put 0.01 into d
repeat with theta = 0 TO pi STEP d
repeat with phi = 0 TO 2*pi STEP d
put COS(theta)^4*SIN(theta) into az
put COS(phi)^2*COS(theta)^2*SIN(theta)^3 into ax
put sumz + az*d*d into sumz
put sumx + ax*d*d into sumx
end repeat
put phi into fld "phi"
Put theta into fld "theta"
end repeat
put (sumz-sumx)/(sumz+2*sumx) into Ao
put Ao into fld "answer"
end mouseUp
Unexpected behaviour within repeat loop
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
When you're in a tight loop, the engine may not be getting enough 'breathing room' for repaint events - and this gets worse if you update a field a few thousand times as it can eat up quite a bit of CPU so it may look like the UI is 'frozen'. Try adding a
right after the line
HTH,
Jan Schenkel.
Code: Select all
wait 0 milliseconds
Code: Select all
put theta into fld "theta"
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
The 'wait' is enough to allow the repaint buffer to kick into action - using 0 milliseconds means your handler will continue to run right after that.
Jan Schenkel.
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com