getScale()[]

I was given help on gui placement below in showcase- and this code was given me:

getScale()[0]

I know what getScale() does but what is the square brackets referring to? (ie [0])

I searched the manual and api reference and it showed no brackets and when I searched the forum I saw several uses of getScale() with and without the brackets but I still have no idea what the square brackets are referring to. AN array or list? A window?

JB SKaggs

[] is an indexing operator in Python (not just in Python, on a sidenote). If you do list[n], that means you get the n’th (first element being at n=0) element from that list, or any other indexable object.
So in this case, it takes the result of getScale(), which is like Vec3(sx, sy, sz), and takes the first element from that, sx.
So it’s merely a more complicated way of doing getSx(). :slight_smile:

Similarly, getScale()[1] would have been the same as getSy(), and getScale()[3] would have been invalid, because the scale only consists of three elements (so the highest value would be 2).

For the beginner that kind of help is invaluable thanks.

jb

Wow, I need to pay more attention to where I post things. I was trying to post a completely unrelated question, and forgot I had an open reply window instead of a new topic window.

Sorry.