Error in adding free-ranging participant text to online experiment

Oh no worries. I appreciate the help so much.
https://pavlovia.org/run/elmiraraeifar/andersen302/html/

Sorry that link does not work. Have you changed the experiment name? This is sometimes the cause of this problem - the experiment filename needs to match the experiment name in your experiment settings.

Ah I did not know that. Ok now the URL is working
URL: https://pavlovia.org/run/elmiraraeifar/andersen302/html/

But it gives an error, though when I refresh it does load to the first page, but then again halts on the textinput page.

So the first problem you need to solve is how you write the text on screen. In the demo I gave above, I used a text component called “text”, and I wrote the text onscreen using text.setText(). You have many text components in your study, but I think the text component you want to write onscreen in your first routine is called text_43. This means that the code I pasted will not work, because I used a text component called “text”, but you need to change the text of a text object called “text_43”. You can change your onscreen text by using text_43.setText(text_43.text + textAdd) etc in place of text.setText(text.text + textAdd).

It is really good practice to name your Builder components with meaningful names, that way you can easily understand what is happening in your code today, and in the future if you come back to your experiment after a break. For example, instead of “text_43”, use “typedText”, or something along those lines :slight_smile:

Thanks a lot for your feedback David. I have added meaningful names to all text and other components in the builder. I cant yet check the textinput code, because for some reason the URL keeps uploading the old experiment and not syncing with the new changes.

Under experiment settings, its set to use the latest version, I even deleted the old project from gitlab.pavlovia. I also checked the last globe (‘view details of project’) and its showing the right folder. But someone the changes are not being shown with the sync.

Is there anything else I can check, in the past I have gotten it to work, where it asks me to ‘create a project’ but this time that window is not showing up. Any thoughts as to what I am doing incorrectly?

Yes, sometimes you need to refresh the browser cache, for some reason or other the browser will not update its cache with your new changes. Try the folllowing (see wiki):

Google Chrome

On Windows and Linux, use one of the following:

  • Hold the Ctrl key and press the F5 key.
  • Hold the ⇧ Shift key and press the F5 key.

On macOS:

  • Hold both the ⌘ Cmd and ⇧ Shift keys and press the R key.

Microsoft Edge

On Windows:

  • Hold the Ctrl key and press the F5 key.[1]

Internet Explorer

Use one of the following:

  • Hold the Ctrl key and press the F5 key.

Firefox and other related browsers

These instructions work for Firefox, SeaMonkey, and other related browsers.

On Windows and Linux, use one of the following:

  • Hold both the Ctrl and ⇧ Shift keys and then press R.

On macOS, use one of the following:

  • Hold both the ⌘ Cmd and ⇧ Shift keys and then press R.

Thank you David! I emptied cache, and now able to create exp. But I’m getting the same issue as before come up again, where this error shows up:

  • when setting the wrap width of TextStim: text_intro
  • no default wrap width for unit: undefined

Then I refresh and it goes away. I have it set at 3.0.6., with ‘height’ for units under screen (under exp preferences) and ‘norm’ selected under general (under PsychoPy preferences).

And when I refresh the font is extremely large and goes off the monitor size.

I would keep your screen units the same, it is not a good idea to start mixing units because they do not correspond with one another. Either use all “Norm” or all “Height”. If you read the link regarding units, you will get an understanding of how to size your units correctly. For example, if your screen units are height, everything is specified relative to the height of the window, where .5 is the top of the screen, and -.5 is the bottom of the screen, in height units. Text will need to be sized accordingly, e.g., size your text as .1 (1 tenth of the height of the screen).

Hi @dvbridges , Thanks for all the feedback. I changed all the experiment settings to norm, as you recommended. The experiment hangs on the first question and doesn’t allow me to enter text (in builder). And when I try to upload it online (using 3.0.6), somehow Im running into a syncing error: “None points to a remote that doesn’t exist (deleted?). What shall we do?”

I tried to upload an old experiment that worked both in builder and online, and I’m getting the same error. I selected “New” under “Pavlovia.org” in headings to upload it. The new experiment’s name shows up on Pavlovia but with no other files and it says “The repository for this project is empty”. I’m not sure where Im making a mistake here. Any help would be much appreciated.

Hi @dvbridges
I was able to upload the experiment and run it online by changing the location of exp (though not 100% certain that’s the reason). In builder, I cannot type text, but when uploaded online it allows me to type text but it doesn’t move to the next question after pressing enter. It types ‘return’ every time I press enter.

I thought this JS code helps this issue. I tried both “frameEnded” and “routineEnded” and they both yield similar results.

}
// check for return (move to next frame):
if (theseKeys.indexOf('return') > -1) {
    psychoJS.experiment.frameEnded = true;
}

(or frame)

Great, glad it is mostly working now. If you want to run the experiment from Builder, you have to make sure that you have the Python code that updates your text onscreen. You can see both Python and JavaScript side by side if you set the Code Type in the code component as “Both”.

To stop the keypresses like ‘return’ and ‘space’ from being printed on screen, you have to change what is added to the temporary textAdd variable. In the example below, return resets the text variables and ends the trial. E.g.,

if (theseKeys.indexOf('return') > -1) {
    textAdd = '';  // Add nothing
    text.setText('')  // empty the onscreen text ready for next input (just be sure to save it)
    continueRoutine = false;  // End routine (if that is what you want)
} else if (theseKeys.indexOf('space') > -1) {
    textAdd = ' ';  // Add a space
}

You will also want to capture shift etc and make sure they are not printed on screen

Hi @dvbridges
I was able to stop the keypresses like shift as well! Thank you for your help/patience as I navigated this process. I learned a great deal and it is much appreciated.
Mira

1 Like

Hi @dvbridges
Sorry to circle back again about this. Everything works smoothly now, but the participant’s .csv output file doesn’t include the free-range text data.

I came across a thread with the code to save, but it’s in python (for Builder).

I tried to convert it to JS using online examples, but it’s not working. Would you please help me with this part as well?

if (textAdd) {
        thisRoutine.addData;
       }

Many thanks,
Mira

Hi @wheights01, try the following:

psychoJS.experiment.addData('textInput', text.text);

Hi @dvbridges
Thank you for the quick reply. I added this code to the exp, and when I run it online, the page shows “loading experiment…” and it doesnt move forward.

if (textAdd) {
    psychoJS.experiment.addData('textInput', text.text);
    }

Also, I added the code under “Each Frame”, I wasn’t sure if it needs to go under “End Routine” or “End Experiment”

Best
Mira

I fixed one error @dvbridges , changing the second text to “text_check1” as this is what its named in my experiment, but Im still getting the same message. I also tried running the experiment with this code under “Each Routine”, and no luck.

if (textAdd) {
    psychoJS.experiment.addData('textInput', text_check1.text);
    }

Thanks a bunch for your help.

Hi, would you mind sharing the URL to your task?

Here it is:
https://pavlovia.org/run/elmiraraeifar/andersen391/html/

Ok, first thing to change is where you save data. Take out the code for saving data from the “Each Frame” tab, this would save data on every frame, or 60 times a second on a 60Hz monitor. In the same block of code in the “Each Frame” tab, make sure that your curly braces close correctly. It looks like you are missing the closing brace } from the block of code used to write the input on screen.

Thanks David, I made those changes and still getting the same message. Just to be sure I got the closing brace correctly:
Under “Each Frame”:

let theseKeys = psychoJS.eventManager.getKeys();
if (theseKeys.length > 0) {  // at least one key was pressed
  textAdd = theseKeys[theseKeys.length-1]; 
  }


// check for quit:
if (theseKeys.indexOf('escape') > -1) {
    psychoJS.experiment.experimentEnded = true;
}
if (theseKeys.indexOf('return') > -1) {
    textAdd = '';  // Add nothing
    text_check1.setText('')  // empty the onscreen text ready for next input (just be sure to save it)
    continueRoutine = false;  // End routine (if that is what you want)
}

if (textAdd) {
    if (theseKeys.indexOf('space') > -1) {
        text_check1.setText(text_check1.text + " ");  
        textAdd = undefined;
    } else if (theseKeys.indexOf('backspace') > -1) {
        text_check1.setText(text_check1.text + textAdd[textAdd.length-1]);  
        textAdd = '';  // Add nothing
        text_check1.setText('')  // empty the onscreen text ready for next input (just be sure to save it)
    } else if (theseKeys.indexOf('lshift') > -1) {
        text_check1.setText(text_check1.text + " ");  
        textAdd = undefined;
    } else if (theseKeys.indexOf('rshift') > -1) {
        text_check1.setText(text_check1.text + " ");  
        textAdd = undefined;
    } else {
        text_check1.setText(text_check1.text + textAdd);  
        textAdd = undefined;
}

And under “End Routine”:

if (textAdd) {
    psychoJS.experiment.addData('textInput', text_check1.text);
}