Millisecond Forums

Add 1 to every item in a list

https://forums.millisecond.com/Topic27849.aspx

By ldb24 - 10/8/2019

Hello,

This may be a basic question but I'm curious about the most efficient way to add a value to each item in a list.

I'm trying to count how many trials there have been since the last time an item was shown (out of a list of 28 items). Right now I have my list of items (say list.stimlistname), then a separate list (list.numSinceLastTrial) to track how many trials it's been since each item was shown (using the selection mode list.stimlistname.current index for list.numSinceLastTrial).

On a given trial where 1 stimulus is shown, I'd like to reset the value for that item in the list.numSinceLastTrial to zero and add 1 to all the other items. Would something like list.numSinceLastTrial.items += 1 work followed by a list.numSinceLastTrial.setitem(0, list.stimlistname.currentindex) to set the current one to 0? Or would I need to do a loop through all items?

Thanks!
By Dave - 10/8/2019

ldb24 - 10/8/2019
Hello,

This may be a basic question but I'm curious about the most efficient way to add a value to each item in a list.

I'm trying to count how many trials there have been since the last time an item was shown (out of a list of 28 items). Right now I have my list of items (say list.stimlistname), then a separate list (list.numSinceLastTrial) to track how many trials it's been since each item was shown (using the selection mode list.stimlistname.current index for list.numSinceLastTrial).

On a given trial where 1 stimulus is shown, I'd like to reset the value for that item in the list.numSinceLastTrial to zero and add 1 to all the other items. Would something like list.numSinceLastTrial.items += 1 work followed by a list.numSinceLastTrial.setitem(0, list.stimlistname.currentindex) to set the current one to 0? Or would I need to do a loop through all items?

Thanks!

You would need to loop through all items.
By ldb24 - 10/8/2019

Okay, I kind of figured but I thought there may be a better solution. Thanks!