z opened this issue on May 02, 2015 · 8 posts
z posted Sat, 02 May 2015 at 11:07 AM
This is my first time using a two column array.
I think I’ve successfully built an array where the first column is one actor, and the second column is a related actor. Now I want to loop through the list and set the parent of the first actor to the second actor.
But I don’t know what the syntax would be to refer to the two columns of my list.
Something like this:
ActorList =[]
ActorList.append ([actor1,actor2])
…
For EachActor in ActorList:
actor1.SetParent(actor2) ----- of course that is not the right syntax, what would be?
structure posted Sat, 02 May 2015 at 1:09 PM Forum Coordinator
This should work
ActorList=[(1,2),(3,4)] actor=ActorList[0][0]
actor.SetParent(ActorList[0][1])
or
ActorList[0][0].SetParent(ActorList[0][1])
Locked Out
z posted Sat, 02 May 2015 at 1:23 PM
Thanks, Struct.
That's very close to what I read online but not quite an answer to my question. Your answer assumes that I know I am on row 0 and I know how many rows there are. I won't. I want to loop.
my question is:
During a looping process how can I refer to the CURRENT row, column 1 and 2?
maybe its:
For EachActor in ActorList:
[EachActor].[0]SetParent([EachActor].[1])
structure posted Sat, 02 May 2015 at 1:29 PM Forum Coordinator
Yes that would work
except your point is in the wrong place.
for EachActor in list:
EachActor[0].SetParent(EachActor[1])
Locked Out
z posted Sat, 02 May 2015 at 3:29 PM
Ah, and no brackets around EachActor got it,
(I was using SQL bracketing [table].[field])
bagginsbill posted Sat, 02 May 2015 at 4:16 PM
I always go for less typing. The iterator can split your pairs for you.
for a, b in yourlist:
a.SetParent(b)
Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)
bagginsbill posted Sat, 02 May 2015 at 4:20 PM
Note:
If you were starting with two separate lists to begin with, you can skip making the list of pairs. The built-in function "zip" will iterate over two or more lists, giving you parallel elements from each - kind of like a zipper bringing the teeth from the two sides together.
for p, c in zip(listOfParents, listOfChildren):
p.SetParent(c)
Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)
structure posted Sun, 03 May 2015 at 5:52 AM Forum Coordinator
Thanks BB, I will have to remember that.
Locked Out