# Unknown position units not defined

**URL:** https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983
**Category:** Online experiments
**Tags:** pavlovia
**Created:** [February 20, 2025, 2:00pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983 "2025-02-20T14:00:50Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![David\_Maitland](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/david_maitland/32/40280_2.png) [@David\_Maitland](https://discourse.psychopy.org/u/David_Maitland)
#### Post date: [February 20, 2025, 2:00pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/1 "2025-02-20T14:00:50Z")

</div>

URL of experiment: [Pavlovia](https://pavlovia.org/Maitland/draganddrop)

Description of the problem:

I am have a new issue having just fixed the last one with the help of the Forums.

The new issue is that when dragging text, I get the below error. I have looked on the Forums and it would seem that many people have been having the same issue, however, as far as I can see there has been no solution. I have tried change the units from height to pixels etc… but still nothing.

 ![Screenshot 2025-02-20 at 13.58.31](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/f/9ffc861026a26647f78098cf87008d5d0eef7145.png)

I am grateful for any help, and hopefully it is fixable.

Thank you!

---

<div class="post-metadata">

### Author: ![jonathan.kominsky](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jonathan.kominsky](https://discourse.psychopy.org/u/jonathan.kominsky)
#### Post date: [February 20, 2025, 2:08pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/2 "2025-02-20T14:08:39Z")

</div>

Oh, it’s probably the same issue actually. This is part of why I suggested just making a TextStim component in the builder, these things are weirdly finicky when you manually define them in code components in PsychoJS (even though it’s usually fine in Python).

So, iteration on the last solution:

```auto
    score_text = new visual.TextStim(
    {"win":psychoJS.window,
    "text": 'Score: ${score}', 
    "pos": [0, 0.4], 
    "height": 0.05, 
    "units": "height", //this guy right here
    "color": "black"});

```

When builder-based components are defined at the beginning of the experiment they can actually take `"units":undefined` and it will be overridden by the window, but I think it doesn’t do that if you manually add a component later in the code. I’m not sure why, that’s definitely a PsychoJS-specific behavior.

Actually, if you’re going to define score\_text in a code component, I strongly recommend putting it in the “begin experiment” or “begin routine” code and just leaving the `score_text.draw()` in the “each frame” code when you want it to appear. Right now you’re re-creating the whole object on every frame, which isn’t ideal.

---

<div class="post-metadata">

### Author: ![David\_Maitland](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/david_maitland/32/40280_2.png) [@David\_Maitland](https://discourse.psychopy.org/u/David_Maitland)
#### Post date: [February 20, 2025, 4:41pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/3 "2025-02-20T16:41:55Z")

</div>

I cannot seem to get this to work, I get the same error as before. I think I am going to try and workout how to create the text component and do the score that way, like you advised.

At the moment (in builder), the score appears on top of the screen in the centre, and then updates every time someone moves a word in the correct box. What is correct and what is not is already defined within the code component.

---

<div class="post-metadata">

### Author: ![jonathan.kominsky](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jonathan.kominsky](https://discourse.psychopy.org/u/jonathan.kominsky)
#### Post date: [February 21, 2025, 7:24am UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/4 "2025-02-21T07:24:53Z")

</div>

Then the issue might be that the units for your other stimuli (which are builder components) are undefined, which is odd. It might have to do with switching the window units back and forth, but you might need to go through each of them and manually set their units to “height”. The bottom line is that the error is coming up because some visual component should have window units and doesn’t, and for some reason it’s not taking the default value from your window settings.

---

<div class="post-metadata">

### Author: ![David\_Maitland](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/david_maitland/32/40280_2.png) [@David\_Maitland](https://discourse.psychopy.org/u/David_Maitland)
#### Post date: [February 24, 2025, 1:18pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/5 "2025-02-24T13:18:14Z")

</div>

I have created the Text component for the score, this shows up when running the programme, however, the score does not update when the participant scores. I have inputted the code print(score), to ensure that the scoring is still working, and it is. The only thing is that it does not update the score on the screen.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 24, 2025, 1:22pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/6 "2025-02-24T13:22:09Z")

</div>

Is the text component set to update each repeat?

---

<div class="post-metadata">

### Author: ![jonathan.kominsky](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jonathan.kominsky](https://discourse.psychopy.org/u/jonathan.kominsky)
#### Post date: [February 24, 2025, 1:29pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/7 "2025-02-24T13:29:30Z")

</div>

Is the component’s text set to “update every frame”?

---

<div class="post-metadata">

### Author: ![David\_Maitland](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/david_maitland/32/40280_2.png) [@David\_Maitland](https://discourse.psychopy.org/u/David_Maitland)
#### Post date: [February 24, 2025, 1:37pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/8 "2025-02-24T13:37:36Z")

</div>

Hi Both,

Thanks for replying, the text was set to update each repeat, I set it to update every frame and now it works!

---

<div class="post-metadata">

### Author: ![David\_Maitland](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/david_maitland/32/40280_2.png) [@David\_Maitland](https://discourse.psychopy.org/u/David_Maitland)
#### Post date: [February 24, 2025, 1:42pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/9 "2025-02-24T13:42:14Z")

</div>

Unfortunately, I have created the text component, and I am still getting the same error when syncing to Pavlovia, ‘Unknown position units: undefined’. Works fine on builder but not on Pavlovia. This issue happens as soon as I click the mouse button.

---

<div class="post-metadata">

### Author: ![jonathan.kominsky](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jonathan.kominsky](https://discourse.psychopy.org/u/jonathan.kominsky)
#### Post date: [February 25, 2025, 8:57pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/10 "2025-02-25T20:57:55Z")

</div>

So there are three possibilities I can think of:

1. This is just a cache-clearing issue. If we’re lucky, you should be able to try the expeirment in an incognito tab and it’ll just work.
2. One of the text elements still doesn’t have defined units. Glancing through the code, this is true of text\_4 and welcome\_text, though I’m not sure why either of those would cause trouble with the mouse since neither of them are part of the drag-and-drop code.
3. It’s something about mouse.isPressedIn with TextStim on PsychoJS. This is not impossible, but it would be more annoying to fix. You might need to manually check a location range or radius around the text instead of using IsPressedIn (i.e., basically make your own isPressedIn function). I hope this isn’t the case, but it’s the only other thing I can think of.

So, fingers crossed that it’s (1) or (2), and if not, it’s still fixable, just more effort.

---

<div class="post-metadata">

### Author: ![David\_Maitland](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/david_maitland/32/40280_2.png) [@David\_Maitland](https://discourse.psychopy.org/u/David_Maitland)
#### Post date: [February 26, 2025, 10:54am UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/11 "2025-02-26T10:54:06Z")

</div>

I really appreciate your help in this!

I firstly started off with your first point and got a new error now (may be a good sign) \* **IndexSizeError: Failed to execute ‘getImageData’ on ‘OffscreenCanvasRenderingContext2D’: The source width is 0.**

I opened the Developers tool to understand where the error takes place, and I could not understand ‘PsychoJS.js:873 IndexSizeError: Failed to execute ‘getImageData’ on ‘OffscreenCanvasRenderingContext2D’: The source width is 0.  
at TextStim.getTextMetrics (TextStim.js:196:41)  
at TextStim.\_estimateBoundingBox (TextStim.js:330:28)  
at new TextStim (TextStim.js:178:8)  
at Scheduler.experimentInit [as \_currentTask] (Drag and Drop.js:131:18)  
at Scheduler.\_runNextTasks (Scheduler.js:225:24)  
at async Scheduler.\_runNextTasks (Scheduler.js:232:13)  
at async update (Scheduler.js:139:18)  
window.onunhandledrejection @ PsychoJS.js:873’

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 26, 2025, 1:37pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/12 "2025-02-26T13:37:32Z")

</div>

> [@David\_Maitland](#):
>
> Drag and Drop.js:131:18)

What is that line?

---

<div class="post-metadata">

### Author: ![David\_Maitland](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/david_maitland/32/40280_2.png) [@David\_Maitland](https://discourse.psychopy.org/u/David_Maitland)
#### Post date: [February 26, 2025, 2:13pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/13 "2025-02-26T14:13:18Z")

</div>

If this refers to line 131 then it would be the name: ‘Welcome\_text’,

However, I am sure that is incorrect and not what you was after, therefore, I am unsure on what line this is, as I have looked through the Java code and cannot see anything that resembles this.

---

<div class="post-metadata">

### Author: ![jonathan.kominsky](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jonathan.kominsky](https://discourse.psychopy.org/u/jonathan.kominsky)
#### Post date: [February 27, 2025, 6:06am UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/14 "2025-02-27T06:06:25Z")

</div>

No that’s correct, it’s line:character number. So something is off with how welcome\_text is put together.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 27, 2025, 4:49pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/15 "2025-02-27T16:49:48Z")

</div>

> [@jonathan.kominsky](#):
>
> `"text": `Score: ${score}`,`

Why does this have backticks?

---

<div class="post-metadata">

### Author: ![jonathan.kominsky](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jonathan.kominsky](https://discourse.psychopy.org/u/jonathan.kominsky)
#### Post date: [February 27, 2025, 5:05pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/16 "2025-02-27T17:05:06Z")

</div>

Lazy copy/paste from a draft of the post I was writing, probably. It should be single quotes, I’ll fix it.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 27, 2025, 5:13pm UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/17 "2025-02-27T17:13:21Z")

</div>

Sorry – my mistake, I thought it was copy-paste from actual code.

---

<div class="post-metadata">

### Author: ![David\_Maitland](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/david_maitland/32/40280_2.png) [@David\_Maitland](https://discourse.psychopy.org/u/David_Maitland)
#### Post date: [March 4, 2025, 9:34am UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/18 "2025-03-04T09:34:00Z")

</div>

I deleted the welcome\_text and I am now getting the original error. I really appreciate the help, but if this is too complicated to fix, I may attempt to recreate this task in another software. Such as Gorilla.

---

<div class="post-metadata">

### Author: ![jonathan.kominsky](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jonathan.kominsky](https://discourse.psychopy.org/u/jonathan.kominsky)
#### Post date: [March 4, 2025, 10:08am UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/19 "2025-03-04T10:08:29Z")

</div>

In fairness I think you’ve discovered a genuine underlying bug that needs to be fixed, and one I’ve never seen before, so it’s a fairly extraordinary occurrence!

I downloaded a copy of your repository and when I have time I’ll mess around with it some more and see what I can figure out. I tried a couple of quick little things and my conclusion so far is that this is definitely a real bug, but a hard one to pin down. It’s something about updating the position of the text objects from the mouse position, but there’s no obvious reason that this should be difficult.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [March 4, 2025, 10:10am UTC](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983/20 "2025-03-04T10:10:51Z")

</div>

I’ve identified your error.

Code of the form `if LeftBox.contains(text_1.pos)` doesn’t make sense.

It should be `if LeftBox.contains(text_1)`, i.e. does the LeftBox object contain the text\_1 object. text\_1.pos is a pair of coordinates, not an object.

Having fixed this, the next error is core.getTime(). How about replacing it with t?

[Next page](https://discourse.psychopy.org/t/unknown-position-units-not-defined/43983.md?page=2)
