Need help for Self Paced Reading Task (v 2023.2.3, Win11)

Hi, I’m new to psychology, and I’m trying to make a self-paced reading task.

I would like to split the words in a sentence based on ‘*’ and show the words one by one when the user presses the spacebar.
The code I wrote is below.


I’ve also included images of Loop and Routine below.



trialsPractice Properties 2024-02-06 오후 11_14_11

When the user completes reading a sentence, I want to show the user a question about the sentence. After that, I want the user to decide if the sentence is correct or not.

The problem is that the code I wrote to make the words show up one by one isn’t working.
I’m not getting any specific errors, but instead of seeing the first word of the sentence and then the next word, I’m seeing the question right away.

How can I get the code to work correctly? Is there something wrong with my code? Please help.

Thanks in advance.

The main thing to test is whether the split is working. For example, you could print(‘nWords’,len(words)) console.log("nWords", words.length);

Hello.
Where should I put the code you mentioned above?
I’m still struggling with the same issue.

I tried your self-paced reading demo, but I don’t know how to modify it for my experiment.

I would really appreciate if you could help me.

Thanks,
Jay.

The code would go straight after the line where you split in Begin Routine. Have you found out how to look at the developer console?

Hi, thanks for the reply.

I thought you meant the console in the page inspector.
How can I access the developer console by any chance?

And is it correct to write the code like this?

words = sentence.split(“*”);
console.log(“nWords”, words.length);

Sorry to bother you, but I’m not used to programming so I have many questions.

Many thanks for your help.
Jay.

That’s probably the same thing and yes that looks right. The info list should show console messages.

Hello.
I ran my experiment in pavlovia and tried to enter the code in the developer console.
But I received this message

Uncaught SyntaxError : Invalid or Unexpected token

in the “*” part of this code.

Maybe instead of separating the words in the sentence with “*”, I should separate them with " "?
(+Tried it, but it didn’t work… :smiling_face_with_tear:)

Thanks for your help.
Jay.

Hello there.

I completely misunderstood your instructions. I’ve edited my reply. :disappointed_relieved:

I added ‘console.log’ to the code as you said, and tried checking the developer console (I followed the tutorial, is this correct?).
However, I couldn’t get any text.

Would these results mean that the split code was not working properly?
If so, how can I modify it so that it works properly?

Thanks for your help.
Jay.

If you can’t see any text put console.log(“Start"); in a Begin Experiment tab to check you’re looking in the right place.

hello.
Thank you for your reply.

I added console.log(“Start”); to the Begin Experiment tab as you suggested.

When I run the experiment, I see the text “Start” in the console.
Then, in the trial that displays words one by one, I see the text “nWords 5”.
(I haven’t edited the code at all since the last time I left a response).

It seems that split is working fine, considering that the nWords is the same as the number of words in the sentence.

Could you please advise on what I need to correct?

Thanks for your help.
Jay.

What is the current issue?

I’m not keen on seeing while clauses in Builder experiments. Could you change it to if? Is the behaviour that you are getting consistent with skimming thought all the words in one frame and then moving on to the question?

The current issue is the same as the first one.
After the first word of the sentence is shown, the next word is not shown.
I don’t think there’s anything wrong with the code I attached, but it doesn’t work.
I would like to know what I need to do so that the words will show sequentially.

Sorry, I believe I didn’t understand your suggestion very well.
I am not very good at coding, so it is difficult for me.
Would you please explain it in more detail?

Thank you for your help.
Jay.

Please could you upload your psyexp file?

Here’s my experiment file. :slightly_smiling_face:

sentResponse has a tick to force end of routine. Remove that if you don’t want it to end the routine.

Personally I do not recommend using JS code components if an Auto code component will do.

Hello. Sorry for the late reply.

If I remove the sentResponse as you suggested, wouldn’t I get the input with spacebar?
And if the sentResponse is causing the current issue, is there any solution other than removing it?

Also, does using a JS component affect the stability of the experiment?

Thanks as always for your responses.
Jay.

Sorry. I meant remove the tick, not remove the component.

JS components are more difficult (for me) to debug.

Oh… I was missing that! :smiling_face_with_tear:
Problem solved.

Thanks to you, I can now move on. I really appreciate your help.
Have a great day. :blush:

Jay.

1 Like