Trouble with run() method for delay script

I’m trying to delay a function that spits out text strings over UDP, but putting it in quotes and using the run() method isn’t giving me any results. in one instance I have the following"

delayProgram = "me.parent().ProgramScene(num , val)"
run(delayProgram, delayFrames = delay)

This raises an error saying that “num” is not defined. It is, and the function works when taken out of this construction.

When I use string formatting to insert the arguments it runs without errors, but the function doesn’t spit out any of the strings.

Anyone know more about how the run() method and what might be going wrong?
Thanks all!

If you are passing a string you need to put it in double quotes and another set of single quotes. Right now you are passing a local variable name to the function which is in a different scope.

run(‘parent().ProgramScene({},{})’.format(2, “‘Delayed Run’”), delayFrames = 30)

-Tim

The string is generated by another function called by the ProgramScene function; the arguments of ProgramScene are integers.

Ok, then you’ll need to just make sure you are passing the value of your variable rather than a reference to it.

Aha! I was confused how to use args[] in the string version of the function, that cleared it up, though. Thank you!

Any chance this somehow works differently in an extension?

This works:
delayProgram = “me.parent().ProgramScene(args[0] , args[1])”
run(delayProgram , num , val , delayFrames = delay)

This doesn’t:
delayStore = “pym.StoreScene( args[0] , args[1] )”
run(delayStore , self.no , self.name, delayFrames = 60)

The only difference seems to be that the second one is part of a class definition and has the self.x type variable.

These two work fine without using the args parameters.

[code]num = 1
val = 2
run(‘parent().ProgramScene({},{})’.format(num,val), delayFrames = 30)

num = 3
val = 4
command = ‘parent().ProgramScene(num, val)’
run(command,delayFrames = 90)[/code]

Where are you calling this function from? Within a class method? Are you getting this error- “NameError: name ‘pym’ is not defined”?

ProgramScene is working fine, and whether or not the functions spit out the strings, I’m not getting any errors. ProgramScene is part of an extension called Scene. StoreScene is part of an extension called PyMaha, which is imported into Scene as pym; StoreScene and RecallScene methods are called at the end of ProgramScene. Here’s what it all looks like in its class without trying to introduce delay:

def ProgramScene(self, scene_number , compiledScene ):

		self.no = scene_number
		self.tup = compiledScene
		self.name = self.tup[0]
		self.dcaList = self.tup[1]
		self.chanList = self.tup[2]


		for dca in self.dcaList:
				# get dca number from self.num
				# get dcas index to use to look up assignments
				# in chanList
			self.num = dca[-1]
			self.index = self.dcaList.index(dca)
			self.chans = self.chanList[self.index]

			for chan in self.chans:
				pym.AssignDCA( self.num , chan )
				pym.SetChanOn( chan , on = "1" )

		pym.StoreScene(self.no , self.name)
		pym.RecallScene(str(1))

The two methods at the end are what I’d actually like to delay.

When you say imported PyMaha as pym, are you creating a new instance of the class? I’ve always gotten a name error when trying to use a run command like that.

If it’s an extension you could just do something like ext.PyMaha.RecallScene() so the run function will be able to find it.