I'm trying to use a python script as an expression in a driver. It was working fine at first and then all of a sudden I get the error message ERROR: Invalid Python expression.
I've tried running the script in the text editor multiple times with no errors, but I get an error in the driver section. Anyone know how to solve this?
Scrip in text
import bpy
prevTime = 0
###
# Rotates the object with the rotSpeed value in radians/s
###
def rotate(rotSpeed, curRot):
scn = bpy.context.scene
curFrame = scn.frame_current
fps = scn.render.fps
# Calculate total playtime
time = curFrame / fps
# Get delta time
dt = time - prevTime
# This will set the current rotation value of the object!!
newRot = curRot + rotSpeed * dt
# Set new previous time
prevTime = time
return newRot
# Add to driver namaespece to make it accessable
bpy.app.driver_namespace['RotWithSpeed'] = rotate
EDIT: The error occurs when I add the line "prevTime = time".
global prevTime
in the rotate method? $\endgroup$