Delay Script Error

Hi all,
I am writing a delay script in a chop execute. The code is followed.

for i in range (7):
delay_script = “print(i)”
run(delay_script, (i + 1), delayFrames = 60 * (i + 1))

Here is the error.

python >>>
Traceback (most recent call last):
File “</project1/chopexec1:print(i)>”, line 1
NameError: name ‘i’ is not defined

Inside the for loop, when I am not using the delay script, the print(i) can print out correctly without error.
But when using delay script, it is said the i is not defined.

Anyone has idea why there is this error?
Thank you in advance!

Hi Akihiko -
As usual, Matthew Ragan has a great write-up of Delay scripts here. Your issue should be pretty simple, though.

In your script delay_script = “print(i)”, the print() function doesn’t know what i is. Instead, you need to pass an argument in to the delay function. So if you do:

delay_script = “print(args[0])”
for i in range (7):
    run(delay_script, (i + 1), delayFrames = 60 * (i + 1))

you should get what you want. The code in delay_script can only access the arguments you pass in, the (i+1) in the run() call.

Good luck!


Thank you so much for your great help!
Perfectly solved!
Thank you!