Hi I was wondering if anyone can help me. I am trying to create a game in visual python and have come to a complete stop. I need to be able to run many while loops at the same time, i have looked into threading but can't get my head around it. Any help would be appreciated, thank you.

I'm guessing that what you want is an event loop:

while True:
    check for events
    respond to events

and then all of your many while loops could be separate events. What do you have in mind?


I am trying to create a 3d blasterball like game. So far I have a box with a ball and bat inside. The ball bounces around in the box and you click and drag the bat were you want it inside the box. I cant get them running at the same time.

I've never used VPython, but the documentation looks accessible. Can you post your code?


Here is the code I have so far:

from visual import*
import time

side= 1
thk= 0.02
dt= 0.005





ball=sphere(pos=(.5,.5,.5),radius= .025)
ball.velocity = vector(0.35,0.25,0.15)

    ball.pos = ball.pos + ball.velocity*dt
    if ball.x+.05>Rs.x:
        ball.velocity.x= -ball.velocity.x
    if ball.x-.05<Ls.x:
        ball.velocity.x= -ball.velocity.x
    if ball.y+.05>Ts.y:
        ball.velocity.y= -ball.velocity.y
    if ball.y-.05<Fs.y:
        ball.velocity.y= -ball.velocity.y
    if ball.z+.05>Tz.z:
        ball.velocity.z= -ball.velocity.z
    if ball.z-.05<F.z:
        ball.velocity.z= -ball.velocity.z



nodes = []
for t in arange(1):
    Bat = box(pos=(0,0.6,0),length=0.2,height=0.125,width=0.02)
    Bat.color = Bat.icolor =(0.5,0.5,1)

drag = None
while 1:
  if scene.mouse.events:
    c = scene.mouse.getevent()
    if drag and (c.drop or c.click):   # drop the selected object
      dp = c.project(normal=scene.up)
      if dp: drag.pos = dp
      drag.color = drag.icolor
      drag = None
    elif c.pick and hasattr(c.pick,"icolor"):   # pick up the object
      drag = c.pick
      drag.color = color.white
  if drag:
   dp = scene.mouse.project(normal=scene.up)
   if dp: drag.pos = dp

I've used Visual Python once before (for about an hour?), but never got the hang of it well. What I have to ask is if Visual Python has some kind of function that automatically updates objects like Pygame does? If so, could just sub-class the box/sphere objects?

Otherwise, threading would be your best bet. I found this threading tutorial to be very helpful. Very clear and easy to understand! Hope this helps!

This question has already been answered. Start a new discussion instead.