I'm trying to periodically update a global variable. The best way I can find to run a timer seems to be to create a very minimal screen with a 'timer' statement in it (is there a better way? I don't know how much overhead there is in creating a screen vs figuring out how to directly start a timer thread or something.)
Anyway, the minimal screen should work, and up to a point it does. I can confirm my function gets called, and it *thinks* it updates the global variable, but the change is never seen outside the function. Is there a screen context gotcha I'm overlooking, or what?
Code: Select all
default g_idle_pose = {}
def idler_set_pose():
global g_idle_pose, g_pose_test
g_idle_pose["eileen"] = "idle1"
g_pose_test = "idle1"
print ("test_set_pose called; g_idle_pose=%r" % g_idle_pose)
screen idler():
timer 3.5 repeat True action Function(idler_set_pose)
label start:
show screen idler
Code: Select all
test_set_pose called; g_idle_pose={'eileen':'idle1'}
> g_idle_pose
{ }
> g_pose_test
NameError: name 'g_pose_test' is not defined
Code: Select all
> idler_set_pose()
None
test_set_pose called; g_idle_pose={'eileen': 'idle1'}
> g_idle_pose
{'eileen': 'idle1'}