Present a routine with an if statement

URL of experiment:
offline experiment: Executive function under stress.psyexp (206.8 KB)

Description of the problem:
I know Pavlovia is off for now but i would still like to try to fix my current issues so when its on i would be able to publish my experiment :slightly_smiling_face:

My experiment involves random tasks assignment-each participant will receive 1 assignment .
I added a routine that presents the texbox that the participant edited.
textbox routine:

the feedback routine will be presented based on an if statement.

if (mymouse_2.isPressedIn(ContinueButton_2)) {
    continueRoutine = true;
} else {
    continueRoutine = false;
}

the feedback routine is based on the e2e_textbox
image

I would like to add that this worked nicely offline when i used the button component. but since button is not yet available online i changed the settings to a text stimuli and it doesn’t work online.
perhaps this code is not relevant online? i could not find info about is in the crib sheet. is there a better way to condition a routine?

thank you!

Is the thing that’s not working clicking on the text stimulus? It used to be the case that clicking on a text stimulus in an online experiment wasn’t possible; you’d need to create a box or something (possibly invisible) in the same position as the text to use as the thing being clicked on. Whether this is still the case or not I don’t know, but if that is indeed the issue you’re having, it might be worth trying to add a box around the text and setting that as your clickable stimulus instead.

the clicking works perfect. the routine ends when clicking on the text. And i can see it stores the click.
The issue is that the next routine is not presented even when I call it in the Begin Routine tab
but perhaps creating a box will be a good ideae anyway since maybe the problem is that
if (mymouse_2.isPressedIn(ContinueButton_2)) {
continueRoutine = true;

is not applicable to a text stimuli. but i am not sure this is the case

I’m not familiar with textbox.getText() though it may be the same as textbox.text

Should it be constant (i.e. is textbox set once in Begin Experiment)?

Text wasn’t clickable online. I’m not sure if and when this was fixed.

textbox is not set in begin experiment

it is set in Begin Routine

window.textbox = textbox;
document.body.setAttribute('data-report', 'textbox');

well i used a polygon before and then changed to the clickable Text and they both worked fine until Yesterday.

That doesn’t look like code I would expect to see in a PsychoPy experiment unless you are embedding an html.

However, I also note that your text component is called textbox so presumably .getText is specific to that (which is a component type I haven’t yet started using).

yes. the getText is specifically aimed to call that component.
i have used e2e_textbox experiment to create that and it worked nicely in presenting every answer each frame. but i wanted to make some changes in the feed back by adding this condition .
it seemed very simple solution to presenting the text to the audience in the end of the experiment and it did work nicely off line
perhaps using embeded html like in your demo would be a good idea too but i am not t o sure how to call it so it will be visible to the participant in the end of the experiment (if he indeed got this condition)

Heya! Let me explain what this code does via some comments:

/* This line assigns the textbox to a window property so that it's globally available (i.e. across multiple routines and/or out of PsychoPy. I tend to use this to debug PsychoPy components using the browser console */
window.textbox = textbox;
/* This line is only for our automated testing systems; it informs our testing script that we're at a particular stage in an experiment */
document.body.setAttribute('data-report', 'textbox');

.getText() is an alternative way to get the text value of a textbox

thank you!
so i presume you define the textbox by creating in the trial routine the text component that is called textbox, correct?
Then, in the feedback routine, the $textbox.getText() you call it so the input will be presented as a text.

I created something similar only i condition it to be presented if a mouse click was clicked in the trial routine. and it seems to ignore it online. i don’t think the issue is in the routine components but perhaps in the way I conditioned the routine.
am i clear? i hope i am

Could you copy-paste your code here? Then I’ll take a peek

this is my code in the Begin Routine tab of the feedback routine

in the trial routine i have a text component named ContinueButton_2
and a mouse component named mymouse_2

Ah I think I know what’s wrong. That isPressedIn will only work in the Each Frame tab of the trial routine. However, based on that you’d like something to happen (or not) in the next routine. So what you could do is pass info from one routine to the other via a variable. For fun I’m giving two versions; a normal one and one with shorter code.

*** Normal version
In the Each Frame tab of trial routine set some variable.

if (mymouse_2.isPressedIn(ContinueButton_2)) {
    window.showFeedback = true;
} else {
    window.showFeedback = false;
}

At the start of feedback routine check that variable.

if (window.showFeedback ) {
    continueRoutine = true;
} else {
    continueRoutine = false;
}

*** Super-short version
You could also write it like this:

window.showFeedback = mymouse_2.isPressedIn(ContinueButton_2);

And…

continueRoutine = window.showFeedback;
1 Like

thank you so much for all the help! very much apricated
love the short version-very neat

1 Like

so now that pavlovia is working and i get to test it. it indeed works but the feedback shows me the content tha i added in the textbox : “Type anything you want here”
instead of the actual input.
in my csv file i can see the content in the textbox.text tab so i know i saved the data

In my tests I’ve got a textbox called textbox1. I get the typed in text like this:

textbox1.getText()

That works when I export to recent versions of PsychoPy (2021.x for sure)

1 Like

and you put it in the feedback text component or the code component?
i have a textbox named texbox
and in the feedback text component i called : $textbox.getText()
image

Yep, like that, but set the dropdown that now no “constant” to “set every repeat”

1 Like

works perfect! cant thank you enough!