Click on and off Text Component

Hello,

I have created the task below in which participants much click on three stocks in a routine, across 10 trials. In each routine the clicked text turns red and after three are selected the routine continues. I would like to give participants the option of clicking on and off a routine in case they change their mind.

https://run.pavlovia.org/scu24/investmentask

I’m not too sure how to go about this and think it will require a restart of the mouse or text components perhaps? Any tips very appreciated!

Best wishes,

Seline

The first thing you will have to do is keep track of the state of each of the stock texts. Usually you could have a boolean value (or a list with boolen values for each of the text components), and set the proper value when you click a text component. Since you are changing the color, you could also use that as a way of investigating the state, i.e.:

if text.color == "white":
    text.color = "red"
else:
   text.color = "white"

I think you might also want to add a button to confirm the final choice (if not, the subject can never change his mind for the final choice).

Hi Christophe,

Thanks for the reply. So I have a list that tracks how many clicks are made before moving onto the next routine.

The clickedN is set to add by +1 each time a new textbox is clicked. See code below

How could this be integrated into the above? Sorry I am a novice with coding and not sure how this could allow the clickedN list to be reduced so that only three are selected per routine.

Thanks,

Seline

It would be much easier for people to help if you paste your code as formatted text rather than as a screenshot – that saves someone from having to type out your code from scratch. Use the </> button in the toolbar so your code gets properly formatted. NB there is inconsistent indenting in your code – the white space is important to Python, and each level should really indent by the same amount, e.g. four spaces for each additional level. At the moment, your indents are mixes of 1, 3, and 4 spaces. It’s easiest to just use the tab key - that will always give you four spaces for each level of indenting.

I’m used to writing code purely within Python using the psychopy module, so not sure if this will fit in. But I would try the following:

  1. Make sure that clicking can toggle the state of the button (starting from line 4):
for clickable in clickables:
   if mouse.isPressedIn(clickable):
      if clickable.name not in clicked_things:
         clicked_things.append(clickable.name)
      else:
         clicked_things.remove(clickable.name)
  1. Give the appropriate color according to the state of the button (line 9):
for clickable in clickables:
   if clickable.name in clicked_things:
      clickable.color = 'red'
   else:
      clickable.color = 'white'
  1. Since we are both adding and removing from clicked_things, we can use the length of that list (line 14, and same adjustment on line 18):
if len(clickables) == 3 and not waiting:
   waiting = True
   startTime = t

Hi Michael,

Thanks for your reply and sorry this is the wrong format and thank you for the notes on my indentation -

clickables = [stock1_text, stock2_text, stock3_text, 
    stock4_text, stock5_text, stock6_text]

for clickable in clickables: 
    if mouse.isPressedIn(clickable):
        clicked_things.append(clickable.name)

clickedN = 0
for clickable in clickables: 
    if clickable.name in clicked_things:
        clickable.color = 'red' 
        clickedN += 1 

if clickedN == 3 and not waiting:
    waiting = True
    startTime = t
   
elif clickedN == 3 and waiting:
    if t > startTime + 0.8:
        continueRoutine = False 

This is the code I am using to implement the process I described above and , again as a novice I might be wrong, but this is where I would need to make my adjustments so that I could allow a participant to click on and off the same text component (or stock).

Seline

Hi Christophe,

I can see what you mean now I think, thanks for sending this. So if the lists were adjusted so clickables could be added or removed then a second click on the same clickable would remove it and it would return to be white?

Best wishes,
Seline