0

I'm using Vizard (Python) and would like to have an event that runs every time the clock is updated. The function to do this properly in Vizard is vizact.ontimer(). The manual for this function can be found here.

The function I'd like to call has both inputs and outputs. I understand that (according to the vizact.ontimer() function manual) I can specify inputs to the function as follows:

vizact.ontimer(0,myFunction,inputs)

...Where inputs is a list of inputs, and myFunction is the name of the function I'd like to run. The 0 simply means that the function should run whenever it gets a chance.

However, I don't know how I can catch the outputs from myFunction. How do I do this? It seems that the vizact.ontimer() function returns an object that bears no resemblance to the output of myFunction.

CaptainProg
  • 5,610
  • 23
  • 71
  • 116
  • what are you hoping the output will be? I am guessing that `vizact.ontimer` isn't going to call the function right away, but at some point in the future. so there isn't anything to return yet. – Corley Brigman Mar 11 '14 at 18:55
  • My function returns a few ints. `vizact.ontimer()` calls the function at regular intervals, specified by the first argument. So, in my example above, the function `myFunction` is called every `0` seconds (i.e. loops immediately). – CaptainProg Mar 19 '14 at 10:25
  • 1
    to be clear (without knowing details of vizard): doing `vizact.ontimer` probably doesn't run the function right away, it _registers_ it to be run sometime in the future (which could be 'as soon as possible'). so its return value won't be related to the function, as it hasn't run it yet. it will run the function at the next timer tick. so, you don't want to depend on returned results; as your solution suggests, you want the function to modify data in place that can be used elsewhere. – Corley Brigman Mar 19 '14 at 13:27
  • Thanks very much. This makes a lot of sense. I'm currently implementing the solution below, which does much as you say. It just involves some quite ugly code (in order to change a variable, I have to append it to a list, then delete list element zero) – CaptainProg Mar 19 '14 at 16:04

1 Answers1

0

The docs dosent seem to specify a way to do this. You could simply work around by passing a list to the function through the args, and have the function append its needed outputs to that list.

EXAMPLE:

>>> def a(x):
    x.append('0')


>>> b = [1,2,3]
>>> a(b)
>>> b
[1, 2, 3, '0']
WeaselFox
  • 7,220
  • 8
  • 44
  • 75
  • Thanks @WeaselFox. How could I do this? Even if I pass a list into myFunction, any changes would surely still be lost if they aren't returned to the parent? – CaptainProg Mar 11 '14 at 14:01
  • nope. If you pass a list to a function, it can be changed. I will add an example for you – WeaselFox Mar 11 '14 at 14:52
  • Thanks @WeaselFox. This workaround seems to be the best solution available, albeit rather awkward. – CaptainProg Mar 19 '14 at 10:27