Add 1 to every item in a list


Author
Message
ldb24
ldb24
Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)
Group: Forum Members
Posts: 13, Visits: 47
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!

Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
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.

ldb24
ldb24
Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)Partner Member (882 reputation)
Group: Forum Members
Posts: 13, Visits: 47
Okay, I kind of figured but I thought there may be a better solution. Thanks!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search