WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-15-2009, 08:06 PM
jaylocco jaylocco is offline
Member
 
Join Date: Jun 2009
Posts: 19
Question Python Programming Question

Im sory to ask this because Im still new to Python. but is there such a thing as 'nested While' in Python just like in C++? Im trying to loop a vizard game which contain a 'while true:' loop. the thing is, how do I repeat the whole program. this is the sample programming code.

Code:
    def game()
        
        yield viztask.waitKeyDown(' ') #<----starts the game
	#fade intro page
	fadeOut = vizact.fadeTo(0,begin=1,time=1)
	startpage.addAction(fadeOut)
	#call throwing function
	throwing ()
	viz.phys.setGravity(0,0,0)

        while True: # this while loop will repeat the flying Aliens to and fro
		FlyAliens() #flies the Aa Bb Cc Aliens
                ResetPositionAliens()     
     myTask = viztask.schedule( game() )

Aliens= [Aa,Bb,Cc]
Ship.enable(viz.COLLIDE_NOTIFY)
		
def oncollide (e) :	
	
	if e.obj2 in Aliens:

		Ship.visible(viz.OFF)
		Shipcrash.visible(viz.ON)
		view.lookat([2,0,-5])
               

viz.callback(viz.COLLIDE_BEGIN_EVENT,oncollide)
Let say if the ship collide with any of the aliens, the ship will crashes down and it will prompt user whether to replay again or not.

So how do we reset the game by using another while loop by pressing the 'r' button ( yield viztask.waitKeyDown('r') ) and back to the beginning. (#<----starts the game)

tq

Last edited by jaylocco; 07-15-2009 at 08:16 PM.
Reply With Quote
  #2  
Old 07-20-2009, 09:54 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
There seems to be a problem with your current code. The while loop inside your game task is not yielding. This will probably cause the graphics loop to freeze. It seems like there should be a yield None statement at the end of the loop.

Regarding your original question. You can setup a simple callback function that restarts the game task when the 'r' key is pressed. Example:
Code:
def ResetGame():
	global myTask
	myTask.kill() # Kill existing task
	myTask = viztask.schedule( game() ) # Create new game task
	
vizact.onkeydown('r',ResetGame)
Reply With Quote
  #3  
Old 07-21-2009, 02:23 AM
jaylocco jaylocco is offline
Member
 
Join Date: Jun 2009
Posts: 19
Thanks..especially for the reset function that u suggested.it makes my life easier..
Reply With Quote
Reply


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
Vizard tech tip: Using the Python Imaging Library (PIL) Jeff Vizard 0 03-23-2009 11:13 AM
General question and question regarding arrays dan12345 Vizard 1 01-15-2008 10:15 AM
python 2.4 instead of 2.3? perselletje Vizard 7 03-14-2006 11:06 AM
Extending Python With C++ Vygreif Vizard 2 01-18-2006 09:21 AM
Use Vizard 2.5 with Python 2.4.1 / IDLE 1.1.1 Gilliard Vizard 4 08-04-2005 11:49 PM


All times are GMT -7. The time now is 04:34 PM.


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