AutoJS issue with "for x,y in" code components

Hello,

I am getting a syntax error in the autoJS section of an experiment I am building. The majority of the code translates perfectly fine, however it seems to have an issue with “for x,y in” code.

In my experiment I have:

for a,b in combinedList:
   if a != b:
      list1.append(a)
      list2.append(b)

I have checked the crib sheet, but cannot see anything in there relating to this, though I might not know the terminology.

Other standard for loops (just the normal “for i in list”) work fine, it just stumbles when the comma goes in.

If anyone knows what needs to be changed to make it JS suitable that would be great.

Best wishes

Hi There,

I am not sure that if valid JS syntax, which is why it doesn’t transpile correctly. What does your combined list look like?

Becca

It starts as empty but then gets populated with
combinedList = [[a1,b1],[a1,b2]] etc depending on responses. The autoJS is happy with all of that as I have to do some zipping and shuffling with the list later, but it just doesn’t seem to be able to translate the Python iteration into JS and I’m not sure how to iterate in JS.

I’ll have more time to explore this next week, but does the following solve the issue?

for Idx in range(len(combinedList)):
   if combinedList[Idx][0] != combinedList[Idx][1]:
      list1.append(combinedList[Idx][0])
      list2.append(combinedList[Idx][1])

for x, y in is a fairly python specific thing, we can look at adding that to the transpiler though :slight_smile: best way to work around it is probably to do:

for xy in combinedList:
    x = xy[0]
    y = xy[1]
1 Like

which would make

for ab in combinedList:
   if ab[0] != ab[1]:
      list1.append(ab[0])
      list2.append(ab[1])
1 Like

Thank you for the speedy replies.

I can’t mark them all as solutions, but in testing they do all work. It now all translates to JS. Hopefully it’s smooth sailing with uploading to Pavlovia.

Thanks again

I’m going to mark my second version as the solution, since it’s far simpler (thanks Todd).