PsychoJS TextStim.setAlignHoriz() function not working

I’m using 2020.1.3

However I think that the beginning of the routine is too late. I put it in Begin Routine of my code_JS component which is in my first routine. My thinking is to align the text after everything has been defined but before anything has been displayed

@wakecarter

To continue my thread (I hope this is not getting confusing as I’m not responding to your latest post), I have v2020.1.3 installed and I’ve been selecting different versions of PsychoPy using the ‘Use PsychoPy version’ dropdown menu in Experiment Settings.

The display comes out as you want (multiple lines of text in a single question left-aligned, and different questions also left-aligned with each other) when I select ‘latest’ as the version. Also when I select ‘v3.2.4’ as the version. But if I select ‘v2020.1.3’ as the version, the display is not right (multiple lines of text in a single question left-aligned, but different questions are sometimes not left-aligned with each other). I’m not sure why ‘latest’ comes out different from v2020.1.3, as v2020.1.3 is the latest version for download on the website, but if it works that’s the main thing. So, my provisional solution is to have v2020.1.3 installed, but to set Experiment Settings to run the ‘latest’ version.

To get my demo program working, the Python code should be;

text3.alignText = ‘left’
text5.alignText = ‘left’

The ‘align’ values for the other text components can be left unspecified, thereby leaving them at their default settings. They don’t need to be set to ‘left’ as these text components don’t contain multiline text.

1 Like

Thank you for your help!

Has there been any luck with single-line text resources? I have quotes I need to display over a template but they all need to start in the same position and are single-line. The only workaround I have done so far is to pre-build the images with the text but I would prefer if they were built in real-time.

Like most people have noted, I have noticed that multi-line text resources left-align automatically on Pavlovia and center locally, without any code. Left align code works locally but not online, but center seems to work online.

Using PsychoPy 2020.1.3.

The Builder file attached to message #6 includes two single-line text components that are left-aligned.

Hm, I’ve tried that solution before but it hasn’t worked for me. Could it be because my text is from Excel? Using PsychoPy 2020.1.3. and Experiment Setting version set to “latest”.

EDIT: Actually, this works for some of my stimuli. The problem is that some of the sentences vary in length (between 30 to 70 characters) and I need my text to fit within an image. It looks like the longer texts seem to start at more or less the same position as the other texts, but then line break and continue at the far left of the screen. Here’s an example (although the quote should begin more to the left):

The shorter versions seem to work well, it looks like the problem only arises when the text gets longer.

PsychoPy version and Experiment Setting version will not affect how the task looks in Pavlovia, so you don’t have to worry about these variables unless you’re having problems with how the display looks when running the task locally in PsychoPy.

I don’t know what you’re doing with images. But with text components, you will certainly run into a problem if the length of the text exceeds the screen width, or the wrap width set for the component. (Note that when no value is entered in the wrap width field in the Advanced tab of a text component, the default wrap width seems to be half of the screen width – a value of 1 when the units are norm or height - so you may need to increase this.) In this case, the text will automatically wrap and the second (wrapped) line will left-align with the first of the spaces that you inserted before the text to get it to line up, which will typically be off the left edge of the screen. In this circumstance, you are actually dealing with a multi-line text component and you need to follow the special instructions for this, i.e. find where the line breaks, split your line of text into two lines at this point, and precede the second line with the same number of spaces that you already have in place for the first line.

I don’t know what you’re doing with images

Image is just serving as a template, but the text needs to start from the same position.

(Note that when no value is entered in the wrap width field in the Advanced tab of a text component, the default wrap width seems to be half of the screen width – a value of 1 when the units are norm or height - so you may need to increase this.)

I actually haven’t tried this out yet and will definitely experiment a bit and see where it takes me.

As you mentioned, certain texts end up becoming multi-line and that complicates things a bit. A tedious task, but will need to comb through every sentence (20 of them) and find where the line breaks and continue from there.

Thanks for the advice!

Yes, a tedious task I’m afraid! It’s a stop-gap until the Form component is implemented on Pavlovia. I haven’t actually done much more with this than the demos that I’ve posted on this forum, and have been using PsyToolkit wherever possible (great for questionnaires and for combining them with simple experiments).

Hi! I am now coming back to this because apparently I have a problem with alignment in another experiment. It only has one line texts, like 1 + 1 or 3 + 4 and it still seems left-aligned on pavlovia. How can it be?