WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Tasks (https://forum.worldviz.com/showthread.php?t=2456)

Moh200jo 01-05-2010 08:53 AM

Tasks
 
I am using collision detection between Box1 and Box2 to count ball lob in a game. I am struggling to calculate balls number depends on this specific collision. I know I have to use function of the collision to do so.
I do not know how I can send information to the task1 from collision function to start add 1 to ball, the code I am using to do so as follows:
To detect the collision between Box1 and Box2 I am using the following code:
Code:

def onCollideBegin(e):
        if e.obj1 == box1 and  e.obj2== box2:
                      print e.obj1 , “    ,” , e.obj2
viz.callback(viz.COLLIDE_BEGIN_EVENT,onCollideBegin)

if collision happened I have to add 1 to ball
Code:

ball=0
def task1():
global ball
        while ball <4:
                yield viztask.waitEvent(viz.COLLIDE_BEGIN_EVENT)
                ball +=1
               
                print 'Number of Balls is : ',sball

In else where in the game function I am using the following line, the game function will quit the game if ball number is 4
Code:

balllob = viztask.waitTask( task1())
I guess I have to use the detection function, but I do not know how can I use it with many tasks relating to each other , as far as I realized Vizard’s documentation also dos not have this.
Thanks,

Jeff 01-05-2010 06:11 PM

You could try creating your own custom event that gets generated whenever certain objects collide. Then in your task function wait for that custom event and increment your counter after that occurs.

Moh200jo 01-07-2010 09:59 AM

Thanks for this, and it is understood
I tried to do the following but still incorrect
Code:

def onCollideBegin(e):
        if e.obj1 == box1 and  e.obj2== box2:
                      print e.obj1 , “    ,” , e.obj2
                      action=vizact.call( task1())
viz.callback(viz.COLLIDE_BEGIN_EVENT,onCollideBegin)
ball=0
def task1():
global ball
        while ball <4:
                yield viztask.waitEvent(action)
                ball +=1
               
                print 'Number of Balls is : ',ball

My problem I do not understand how can connect these functions
Any help?

Moh200jo 01-08-2010 04:34 AM

I have tried to use box1.collidingwith(box2) but this made the game meet the condition once I run the code

Code:

ball=0
def task1():
global ball
        while ball <4:
                action=box1.collidingwith(box2)
                yield viztask.waitEvent(action)
                ball +=1
               
                print 'Number of Balls is : ',ball


Jeff 01-08-2010 08:48 AM

There a few ways you could do this. You could use viztask's signal and wait functions and send a signal when the collision of those objects occurs within your onCollideBegin function. Then wait for that signal in your task function.

Or you could create a custom event that is generated when those two objects collide and wait for that event in your task function. The docs describe how to create a custom event.

Moh200jo 01-08-2010 11:53 AM

Well, what is I can not do it in Vizard to send a signal from the function to the task.

may you can gipost an example of this (sending a signal from a fuction to a task)? I do not find any on the documentation

Jeff 01-08-2010 02:41 PM

Take a look toward the bottom of the following page. There is an example there for using signalling with tasks.

http://www.worldviz.com/vizhelp/VizTask_basics.htm


All times are GMT -7. The time now is 06:58 AM.

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