WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-02-2009, 10:34 AM
jvacare1 jvacare1 is offline
Member
 
Join Date: Aug 2009
Posts: 6
beginner flow control question

Hello everyone,

I have a beginner's question on flow control that I couldn't find an answer to with forum topic search.

My script involves the MainView navigating a maze. There are "setup" hotspots in various locations which set up other "trial" hotspots, which are the ones in which we are interested. The hotspots are working great, but when the MainView reaches the trial hotspot, I would like to do the following:

1. Move the MainView to a specific location
2. Present the user with a text choice
3. Halt all script and inputs until the user presses one of two keys
4. Move the MainView to one of two destinations depending on the keypress

Number 3 is the one I'm having trouble with. I would like to make it such that until the user presses one of two keys, the only action that can be taken is that the MainView can pivot. I would like to make it so that the MainView cannot move through inputs, and that the this condition will last until one of two keys are pressed.

I'm familiar with events but don't see how I can "shut down" the Vizard environment until the appropriate keyevent fires.

Any help is greatly appreciated!

Jason
Reply With Quote
  #2  
Old 08-03-2009, 05:04 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I'm not sure what you mean by "shutting down the Vizard environment".

In general though, it sounds like you should be using the viztask module. The documentation describes how to use tasks, and they are ideal for controlling the flow of a script in stages. You would probably implement each stage as a subtask and have a high-level main task that simply runs each stage consecutively.

Let me know if you have more specific questions.
Reply With Quote
  #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
  #4  
Old 08-31-2009, 11:30 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
How are you moving around? If you are using the mouse you could just disable mouse navigation.
Code:
viz.mouse(viz.OFF)
Reply With Quote
  #5  
Old 09-14-2009, 08:19 AM
jvacare1 jvacare1 is offline
Member
 
Join Date: Aug 2009
Posts: 6
Ah! That sounds so simple. I am indeed using a mouse while in debug mode. In the actual trials there will be a visor and motion capture, but I'll tackle the code to disable that in the future.

Thanks!
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
adding more than 1 action for avatar animation slider control yak Vizard 0 07-21-2009 11:22 AM
orientation question whj Vizard 3 01-21-2009 11:22 AM
Control of timers vizmaster Vizard 6 08-22-2008 09:36 AM
General question and question regarding arrays dan12345 Vizard 1 01-15-2008 10:15 AM
to rephrase my question... shai Vizard 2 10-27-2004 10:55 AM


All times are GMT -7. The time now is 09:50 AM.


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