The attached solution works, though I did not yet check if the signal is sent at the correct window flip.
Instead of counting the frames, the iterations of the loop are counted to track the number of presented words (since each word requires one iteration of the loop).
This goes into the Begin routine-tab:
# get the sentence for this trial and split it into a list of words:
words = sentence.split()
# count the words:
numWords = len(words)
# duration to display the text component:
totalDuration = 0.001 + (numWords * 0.5) # time in seconds
# loop to display words and send triggers:
for idx, word in enumerate(words):
currentWord = idx+1 # track the current word
text_15.setText(word) #set current word in Builder placeholder text variable
if currentWord == trig_w1: # trigger word 1
p_port.setData(trig_1) # send trigger 1
if currentWord == trig_w2: # trigger word 2
p_port.setData(trig_2) # send trigger 2
if currentWord == trig_w3: # trigger word 3
p_port.setData(trig_3) # send trigger 3
for frameN in range (18):
text_15.draw() #present current word for 18 frames (at 60Hz!)
win.flip()
for frameN in range(12): #present blank screen for 12 frames (at 60Hz!)
win.flip()
p_port.setData(0) # reset the port
test5.psyexp (161.8 KB) expe_test.xlsx (5.6 KB)