Change stimulus properties for a specific amount of time

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v2020.2.10
Standard Standalone? (y/n) If not then what?: yes
**What are you trying to achieve?:
Hi,

this seems like a rather simple question but I couldn’t really figure out how to do that:
I am trying to change the color of a polygon for 1 second after a valid mouse click.

What did you try to make it work?:

if mouse.isPressedIn(polygon_3):
   while XY 
        polygon_3.fillColor = 'yellow' 

I have tried several code snippets for the placeholder XY. For instance using a timer, but then realized that a timer would add time to my time zero and create a time lag.

I think you where on the right path with a timer. You could modify your code like this:

#in the begin routine tab
timer = core.Clock()
polygon_3.fillColor = 'white' #the color you want the polygon to normaly have

#in the each frame tab
if mouse.isPressedIn(polygon_3):
   timer.reset() #turn the timer back to 0
   polygon_3.fillColor = 'yellow'

if timer.getTime() >= 1:
   polygon_3.fillColor = 'white' #1 second after clicking on the polygon it becames white again

tandy

1 Like

Hi tandy,

that makes so much sense. Thank you so much, it works perfectly. I guess I was a little confused with the timer function.

Thanks,

Kathrin

Hi tandy,
after implementing that I ran into a new problem. I was trying to run this experiment on pavlovia but got an error message rearding to the core.Clock() function. After looking in the crib sheet I figuered I would have to implement the JS code. I tried this:

timer = new util.Clock();
for (var stim, _pj_c = 0, _pj_a = [Probe_Pos_1, Probe_Pos_2, Probe_Pos_3, Probe_Pos_4, Probe_Pos_5, Probe_Pos_6, Probe_Pos_7, Probe_Pos_8, Probe_Pos_9], _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
    stim = _pj_a[_pj_c];
    stim.fillColor = "black";
    stim.lineColor = "black";
    }

But when I start it from the builder I get an Sytax error: invalid syntax.
Have you ever implemented this kind of code for an online study? and do you know if I can flexibly use pythin and JS code in the custom code components?

Hello Kathrin

define the JavaScript timer in its own JS code-element. Leave the code-element that autotranslates Python to JavaScript untouched. Alternatively, you could set the code-element from autotranslate to both and edit the JavaScript part.

Best wishes Jens

1 Like

Hi,

Thanks a lot! I already did that and it seems to be working in pavlovia. But now I can’t start it locally. Is it supposed to be like this? I mean it’s not a deal breaker, I could just test it online but maybe I’m doing something work.
Anyway, I’m sorry for all the questions, but I realized that my loop is also not working as soon as I switch to pavlovia. I have a condition sheet in which I define the opacity of every element. I broke my experiment down to only display the circles (3 trials, 10 seconds each). Instead of changing the opacity after 10 seconds, I get the same condition for 30 seconds. From the results file I can download I can see that I get only measurements for the first trial.
In my builder I set the opacity to change every repeat. Any idea where this error might come from?

Again, thanks a lot in advance!

Best,

Kathrin

Hello Kathrin

well, it should work offline and online if you have set autotranslate to both or if you define two code-elements, one Python only, the other JavaScript only.

For the other problem, do you have a toy-experiment which exemplifies the problem?

Best wishes Jens

So in the code component you have two windows, one for phyton (local) and one for javascript (online). For the experiment to work both online and offline you should have a working code in both windows. However if you are going to test your experiment online I think you can focus only on that.

For the changing opacity it is known that it gives some problem online. I suggest you to search the forum because I think there is a thread somewhere with a fix for this problem. Alternatively, you can change the color of the circles: if you want them to disappear for example you can change the fillcolor to the background color.

tandy

Hi,

@tandy: thanks for the hint. It’s really a known issue. My work around is changing the colors for now and it seems to be working. The python -> JS crib sheet was really helpful.

@JensBoelte: It works since I used “both” and twisted the JS code according to the crib sheet. But I was wondering how to make the project on pavlovia public to be able to share it in this forum for example. I’m not sure if i’m missing something completely but I only found the members setting where I can add members to the project. I don’t have a licence or credits yet, but I thought there would be a way to share the project anyways.

Thank you so much!

Kathrin

Hello

Open your project on gitlab, settings, permissions, public

Best wishes Jens

1 Like