WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Wait for function to return? (https://forum.worldviz.com/showthread.php?t=2686)

Josh 04-14-2010 01:03 PM

Wait for function to return?
 
Hi all

I want to stop the execution of my script until a function returns.

The idea is to stop the script when starting a task, where the user has to press a key (P), and as soon as he presses the key, the script should continue.

Code:

class Experiment:

        # This method is called somewhere...
        def start_green_face_task(self):
                self.avatar_to_morph().make_green_face()
                self.test_reaction_time() # Here the code should stop until this method returns (when the user presses P)! But how can this be achieved?
                self.end_green_face_task() # This method should be called *after* the user presses P!
               
        def test_reaction_time(self):
                while True:
                        yield self.viztask.waitKeyDown('P', d)
                        return
               
        def end_green_face_task(self):
                self.avatar_to_morph().remove_green_face()

Sadly I don't get it to work... I tried stuff like

yield self.test_reaction_time()

or

self.viztask.schedule(self.test_reaction_time())

but somehow this doesn't do what I need...

Thanks very much for help!
Josh

Josh 04-15-2010 06:11 AM

Please, this is very important for me... Anyone??

Josh 04-15-2010 12:43 PM

*Push* (I'm sorry, but it's very important that I get this to work asap)

IGoudt 04-15-2010 01:45 PM

Exactly *what* does not work? On which line does the program do other than you expect it to do?
Following changes might not work, but at least it should call test_reaction_time() correctly. Issue is that end_green_face_task() will run at the same time (I think). You can move that method call to test_reaction_time() as well, but why do you need a viztask for a key event? You can also register the P button with the function end_green_face_task()
Code:

class Experiment:

        # This method is called somewhere...
        def start_green_face_task(self):
                self.avatar_to_morph().make_green_face()
                viztask.schedule(self.test_reaction_time()) # Here the code should stop until this method returns (when the user presses P)! But how can this be achieved?
                self.end_green_face_task() # This method should be called *after* the user presses P!
               
        def test_reaction_time(self):
                yield viztask.waitKeyDown('P')
               
               
        def end_green_face_task(self):
                self.avatar_to_morph().remove_green_face()


farshizzo 04-15-2010 02:11 PM

I believe the following code should do what you want:
Code:

class Experiment:

        # This method is called somewhere...
        def start_green_face_task(self):
                viztask.schedule( self.test_reaction_time() )
               
        def test_reaction_time(self):
                self.avatar_to_morph().make_green_face()
                yield viztask.waitKeyDown('P') # Here the code should stop until this method returns (when the user presses P)! But how can this be achieved?
                self.end_green_face_task() # This method should be called *after* the user presses P!
               
        def end_green_face_task(self):
                self.avatar_to_morph().remove_green_face()



All times are GMT -7. The time now is 09:21 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC