View Single Post
  #1  
Old 04-08-2016, 07:44 AM
jelly jelly is offline
Member
 
Join Date: Feb 2016
Posts: 38
Smile help with triggering an action

Hello!

I have a small problem because I don't know how to combine two actions.

I have a small texquad on the upper left corner of the screen and a list fo 4 pictures, that will be shown one after the other as textures to the quad. I want my trial function to go though all 4 pictures in the list. A left mouse button click shoul trigger the next picture. However, I want this to happen, only when the left mouse button is clicked AND when it is placed over the textquad (basically selecting the picture), but not when the lft mouse button is clicked anywhere else on the screen. Do you have any pointers that would get me in the right direction?

(I am a beginner with programming, I am not asking for debugging, this is just to see whether my rationale is completely off or whether I am already on the right track)

Here is what I have so far:

Code:


##########################

import viz 													
import vizshape												
import viztask												
import vizinput												
import time													
import random												
import linecache												
import vizact												
import itertools


viz.setMultiSample(4) 												
viz.fov(45)

#Start Vizard														
viz.go()

####~~~~~~~Setup~~~~~~~####

viz.mouse.setOverride(viz.ON)


#Set background colour
viz.clearcolor(viz.GRAY)				

#Make a screen window:
screen1 = viz.addTexQuad(size=0.5)            
screen1.setPosition([0.5,2.2,1.3])
screen1.setSize([0.2, 0.2])
screen1.setTexQuadDisplayMode(viz.TEXQUAD_FIXED)
screen1.visible(viz.ON)

myList = ['sil1.png', 'sil2.png', 'sil3.png', 'sil4.png']
myListIndex = 0

def click():
	object = viz.pick()
	if object == screen1:
		print 'picture'
		vizact.onmousedown(viz.MOUSEBUTTON_LEFT, click)

def trial():
	global myListIndex
	screen1.visible(viz.ON)
	for x in range(4):
		picture = viz.add(myList[myListIndex])
		screen1.texture(picture)
		viz.mouse.setVisible(viz.ON)
		vizact.onmousedown(viz.MOUSEBUTTON_LEFT, click)
		yield viztask.waitTime(3)
		myListIndex = myListIndex + 1
	screen1.visible(viz.OFF)


viztask.schedule(trial())

Thank you very much in advance for the help!

Best,
jelly
Reply With Quote