WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 11 votes, 5.00 average. Display Modes
  #1  
Old 08-04-2004, 09:22 AM
vrlab vrlab is offline
Member
 
Join Date: Jul 2004
Posts: 4
switch statement

Hello,

I am trying to write a switch statement in my vizard script. I am using version 2.1 and I found on the internet that version 2.3 supports the switch function. This is the switch part of my script:

elif num == WAIT_BUTTON1:
data = sid.get()
buttonstate = sid.buttons()
switch(buttonstate):
case 'one':
if buttonstate == sid.BUTTON1:
button1 = 1

case 'two':
if buttonstate == sid.BUTTON2:
button2 = 2

case 'three':
if buttonstate == sid.BUTTON3:
button3 = 3

case 'four':
if buttonstate == sid.BUTTON4:
button4 = 4

case 'five':
if data[2] == 8:
viz.callback(viz.TIMER_EVENT, 'HandleTimer')
viz.starttimer(SAVE_DATA)




this script is not running, and I was wondering if it is because i need version 2.3 of python instead of version 2.1. It could also be a problem with the syntax too. If the problem is that I'm using 2.1 instead of 2.3, how do i upgrade it? I appreciate any help. Thank you in advance.
Reply With Quote
  #2  
Old 08-04-2004, 10:23 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

The latest version of Vizard uses python 2.3, however python does not support the switch statement. The equivalent of this in python is to do if ... elif ... elif ...

On a side note, to check if a joystick button is down you would do the following:
Code:
buttonstate = sid.buttons()
if buttonstate & sid.BUTTON1:
	print 'button 1 is down'

if buttonstate & sid.BUTTON2:
	print 'button 2 is down'

if buttonstate & sid.BUTTON3:
	print 'button 3 is down'

if buttonstate & sid.BUTTON4:
	print 'button 4 is down'
The button state is a bitmask, where each bit represents the state of a corresponding button. Therefore you have to perform a bitwise AND to check if a button is down.
Alternatively, you could setup a callback to notify you when a joystick button is pressed. There is an example script that shows how to use the sid library under C:\Program Files\Vizard20\examples\input\joystick.py

Please let me know if you need any more help.
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


All times are GMT -7. The time now is 11:25 AM.


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