LISTS: Assign a value to an element of a list

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

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.

Use a script

# 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!

1 Like

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. :slight_smile:


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

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


Yes, I will try by means of Script. Thaks