ScriptSpot

Forum topic · General Scripting

progress ESC

By JokerMartini · 2011-10-19

Description

How do I make it so when the user hits the ESC key the operation is completely stopped and canceled....
I've been trying to trouble shoot this and the help file is not really explaining it well enough in a way that is making sense.

Thanks

John


startFrame = animationRange.start
endFrame = animationRange.end
frameCount = endFrame - startFrame
step = 1
prgCount = 0

progressStart "Go:"
for t = startFrame to endFrame by step do
(
if keyboard.escPressed then
exit with (escapeEnable = false; progressEnd(); format "Canceled\n")
else (
sliderTime = t

progPerct = (100.0 * prgCount * step / frameCount) as integer --//ProgressValue
progressUpdate progPerct
prgCount += 1
)
)
progressEnd()

Comments (5)

JokerMartini · 2011-10-19

I have implemented what you have written but once I uncomment the

progressStart "Go:"
progressUpdate progPerct
progressEnd()

And run the script I continualy get this "Question" dialog which pops up and whether i hit yes or no it still runs the for loop.....hmmm?

Anubis · 2011-10-20

Yeah, the PBar is very capricious feature :)
I remember that changing

escapeEnable

not help,
and the ESC key messed up with the PBar cancelation.

The fix is to use other key than ESC, Ctrl for example.
Also sometime needs to set progressUpdate 100.

In other words, replace last lines:

stop = keyboard.controlPressed
)
progressEnd()

with:

stop = keyboard.controlPressed
)
progressUpdate 100
progressEnd()

Anubis · 2011-10-19

An easy made logical mistake, I think. Your Exit break only stop the progressbar but not the for-loop. You can fix that with boolean pointer into the for-loop (using while), something like:

startFrame = animationRange.start
endFrame = animationRange.end
step = 0.1

frameCount = (endFrame - startFrame + 1) / step
-----------
prgCount = 0
stop = false -----------
progPerct = 0

progressStart "Go:"
for t = startFrame to endFrame by step while not stop do
(
	sliderTime = t
	--format "I'm at frame: %\n" t
	
	prgCount += 1
	progPerct = (100.0 * prgCount * step / frameCount) as integer
	progressUpdate progPerct
	
	stop = keyboard.escPressed -----------
)
progressEnd()

if prgCount < frameCount do
	format "Canceled at frame: %\n" sliderTime
format "Progress done: %\%\n" progPerct

MZP

JokerMartini · 2011-10-19

they are un-readable files?

miauu · 2011-10-19

I don't have time to find out and post the code, but download RTTAssist and check EXPLODE function. You can see haw I use ESC key to stop explosion.