# LISTS: Assign a value to an element of a list

**URL:** <https://forum.universal-robots.com/t/lists-assign-a-value-to-an-element-of-a-list/21763>\
**Category:** URScript\
**Created:** [June 5, 2022, 3:26pm UTC](https://forum.universal-robots.com/t/lists-assign-a-value-to-an-element-of-a-list/21763 "2022-06-05T15:26:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![joperez](https://avatars.discourse-cdn.com/v4/letter/j/f08c70/32.png) [@joperez](https://forum.universal-robots.com/u/joperez)\
**Post date:** [June 5, 2022, 3:26pm UTC](https://forum.universal-robots.com/t/lists-assign-a-value-to-an-element-of-a-list/21763/1 "2022-06-05T15:26:17Z")

</div>

Hello averyone:

In an UR3, when programing:

- I define aa as a list → aa:=[0,0,0,0,0,0]
- I define j as an integer–\> j:=2

I try to assign a value to an element of a list, but when I select “assigment” and I type aa[j]:= the message “Illegal variable name” apperars and is not possible to modify the element of the list.

Any help is welcome to modify an individual value of an element of the list, being the index defined by a variable.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![jarrah.l](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@jarrah.l](https://forum.universal-robots.com/u/jarrah.l)\
**Post date:** [June 5, 2022, 9:19pm UTC](https://forum.universal-robots.com/t/lists-assign-a-value-to-an-element-of-a-list/21763/2 "2022-06-05T21:19:41Z")

</div>

Hey mate,

Not 100% sure, but maybe the varible j is used in joint moves so it is an “illegal variable name”. Try calling it something else and see what happens.

---

<div class="post-metadata">

**Author:** ![MikeM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/mikem/32/3114_2.png) [@MikeM](https://forum.universal-robots.com/u/MikeM)\
**Post date:** [June 6, 2022, 10:44am UTC](https://forum.universal-robots.com/t/lists-assign-a-value-to-an-element-of-a-list/21763/3 "2022-06-06T10:44:29Z")

</div>

Use a script

```auto
# assignment - array
aa := [0,0,0,0,0,0]

# assignment - pose
ab := p[0,0,0,0,0,0]

# assignment - index value
j := 2

# script - modify array
aa[j] = 3
# returns aa := [0,0,3,0,0,0]

# script - modify pose
ab[j] = 1.2345
# returns ab := p[0,0,1.2345,0,0,0]

```

Poses are different then arrays, **CAREFUL** sometime Polyscope commands require **ARRAYS** and some **POSES**

Hope that helps and best of luck!

---

<div class="post-metadata">

**Author:** ![efn](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@efn](https://forum.universal-robots.com/u/efn)\
**Post date:** [June 7, 2022, 9:44am UTC](https://forum.universal-robots.com/t/lists-assign-a-value-to-an-element-of-a-list/21763/4 "2022-06-07T09:44:13Z")

</div>

I had no trouble getting this to work in the simulator.

It sounds like you’re trying to use the command _Assignment_ to assign the single value to the array. You should use _Script_ command instead to assign a value to a single index. 🙂

![1](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/1/17ea54149407358c1f00da85606e73a240d6c4c0.png)

---

<div class="post-metadata">

**Author:** ![joperez](https://avatars.discourse-cdn.com/v4/letter/j/f08c70/32.png) [@joperez](https://forum.universal-robots.com/u/joperez)\
**Post date:** [June 7, 2022, 10:32am UTC](https://forum.universal-robots.com/t/lists-assign-a-value-to-an-element-of-a-list/21763/5 "2022-06-07T10:32:11Z")

</div>

Thanks, but I have tried with other names for the index and this is not the solution.

---

<div class="post-metadata">

**Author:** ![joperez](https://avatars.discourse-cdn.com/v4/letter/j/f08c70/32.png) [@joperez](https://forum.universal-robots.com/u/joperez)\
**Post date:** [June 7, 2022, 10:33am UTC](https://forum.universal-robots.com/t/lists-assign-a-value-to-an-element-of-a-list/21763/6 "2022-06-07T10:33:54Z")

</div>

I will try it, it sounds very well. I will use # script - modify array

Thanks

---

<div class="post-metadata">

**Author:** ![joperez](https://avatars.discourse-cdn.com/v4/letter/j/f08c70/32.png) [@joperez](https://forum.universal-robots.com/u/joperez)\
**Post date:** [June 7, 2022, 10:35am UTC](https://forum.universal-robots.com/t/lists-assign-a-value-to-an-element-of-a-list/21763/7 "2022-06-07T10:35:05Z")

</div>

Yes, I will try by means of Script. Thaks

---

<div class="post-metadata">

**Author:** ![jenniferluna9087](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@jenniferluna9087](https://forum.universal-robots.com/u/jenniferluna9087)\
**Post date:** [April 24, 2024, 7:53am UTC](https://forum.universal-robots.com/t/lists-assign-a-value-to-an-element-of-a-list/21763/8 "2024-04-24T07:53:12Z")

</div>

Assigning values to elements of a list may seem straightforward, but nuances can arise. That’s where [cheap essay writers Uk](https://ukessaywritingservice.co.uk/) come in handy. With their expertise, you can ensure clarity and efficiency in your code. It’s a smart move for streamlining tasks and gaining valuable insights.

---

<div class="post-metadata">

**Author:** ![gavin.theobald](https://avatars.discourse-cdn.com/v4/letter/g/7feea3/32.png) [@gavin.theobald](https://forum.universal-robots.com/u/gavin.theobald)\
**Post date:** [July 31, 2024, 8:27am UTC](https://forum.universal-robots.com/t/lists-assign-a-value-to-an-element-of-a-list/21763/9 "2024-07-31T08:27:56Z")

</div>

You can write to a list.

I have a list.  
Var5= (true, true, true, true)

Use script  
Var5[2] = false

Var5 now = ( true, true, false, true)
