View Single Post
  #3  
Old 08-30-2009, 08:40 AM
jvacare1 jvacare1 is offline
Member
 
Join Date: Aug 2009
Posts: 6
Question More specific flow control questions

Thanks for the reply. I had looked at tasks initially, but got a little lost in their implementation. After your suggestion that they are the appropriate way to proceed, I took a closer look.

I integrated my task into a hot spot event. When a particular hot spot is entered it executes a hot spot event handler, which schedules the desired task:

Code:
# define the hotspot events
SETUP1, SETUP2, TRIAL = 1, 2, 3
def HotSpotHandler(id, x, y, z):
  if id == TRIAL:
    viztask.schedule(PerformTrialTask)
  else:
    viz.starthotspot(TRIAL, viz.RECTANGLE_HOTSPOT_IN, 0, 4, 2, .5)
viz.callback(viz.HOTSPOT_EVENT, HotSpotHandler)
viz.starthotspot(SETUP1, viz.RECTANGLE_HOTSPOT_IN, -20, 10, 2, .5)
viz.starthotspot(SETUP2, viz.RECTANGLE_HOTSPOT_IN, 20, 10, 2, .5)

# perform the trial task
def PerformTrialTask():
  while True:
    # prepare the next setup hot spots
    viz.starthotspot(SETUP1, viz.RECTANGLE_HOTSPOT_IN, -20, 10, 2, .5)
    viz.starthotspot(SETUP2, viz.RECTANGLE_HOTSPOT_IN, 20, 10, 2, .5)

    # move into position
    viz.MainView.goto([0, 1.82, 4])
    viz.MainView.lookat(PitCover.getPosition())
		
    # process question
    yield TrialSubTask()

# sub task to handle question / answer
def TrialSubTask():
  while True:
    global PromptText
    PromptText = viz.addText('What will you do?\n\n\'J\' - Try to jump over.\n\'A\' - Use assistance.', viz.SCREEN, scene=1)
    PromptText.setScale([.5, .5, 1])
    PromptText.translate(0.05, 0.9)
    DataObject = viz.Data
    yield viztask.waitEvent(viz.KEYDOWN_EVENT, DataObject)

    # process answer
    PromptText.remove()
    if DataObject.data[0] == 'j':
      viz.MainView.goto([0, 1.82, 9], 5, viz.SPEED)
      viz.MainView.lookat(0, 1.82, 100)
      return;
    elif DataObject.data[0] == 'a':
      viz.MainView.goto([0, 1.82, 7], 5, viz.SPEED)
      viz.MainView.lookat(0, 1.82, 100)
      return;
This seems to function as expected except that when I run the script I am still able to navigate the view point around while the task is waiting for the KEYDOWN_EVENT. We want the simulation to essentially ignore all input except for the two keypresses. I thought the "while True" loops might accomplish this, as presented in the tutorial, but I am still able to navigate around the maze while the task is running and waiting.

Can you describe how I might prevent that navigation? Let me know if this question isn't specific enough and I'll try again.

Thanks,

Jason
Reply With Quote