Please use our GitHub Issues page for all new support inquiries. If you need to contact us directly, please e-mail [email protected]

Hey all, I'm trying to formulate a reliability print script for someone, and with the information I presented, the script is continuously looping. After running, the script generates over 800 lines of data (mostly repeating). Is there a way to detect where I'm instructing the code to loop, so I can fix it? Please let me know.

begin

# Get our variables

control = getVariable("CONTROL") seat = getVariable("SEAT") foam = getVariable("FOAM") rel_control = getVariable("RELCONTROL") rel_seat = getVariable("RELSEAT") rel_foam = getVariable("RELFOAM")

  for ccell in control.cells

        for scell in seat.cells

              for fcell in foam.cells

                                for rccell in rel_control.cells

                                      for rscell in rel_seat.cells

                                            for rfcell in rel_foam.cells

                                                                                                       #FINALLY we have everything, so print

print ccell.offset.to_s + "t" + rccell.offset.to_s + "t" + ccell.trialnum + "t" + rccell.trialnum + "t" + scell.side + "t" + rscell.side + "t" + ccell.choice + "t" + rccell.choice + "t" + ccell.sitshift + "t" + rccell.sitshift + "t" + ccell.dirshift + "t" + rccell.dirshift + "t" + ccell.lookoth + "t" + rccell.lookoth + "t" + ccell.reach + "t"

scell.offset.to_s + "t" + rscell.offset.to_s + "t" + scell.trialnum + "t" + rscell.trialnum + "t" + scell.side + "t" + rscell.side + "t" + scell.choice + "t" + rscell.choice + "t" + scell.sitshift + "t" + rscell.sitshift + "t" + scell.dirshift + "t" + rscell.dirshift + "t" + scell.lookoth + "t" + rscell.lookoth + "t" + scell.reach + "t" + rscell.reach + "t"

fcell.offset.to_s + "t" + rfcell.offset.to_s + "t" + fcell.trialnum + "t" + rfcell.trialnum + "t" + fcell.side + "t" + rfcell.side + "t" + fcell.choice + "t" + rfcell.choice + "t" + fcell.sitshift + "t" + rfcell.sitshift + "t" + fcell.dirshift + "t" + rfcell.dirshift + "t" + fcell.lookoth + "t" + rfcell.lookoth + "t" + fcell.reach + "t" + rfcell.reach + "n"

                                                     end
                                                  end
                                               end
                                            end
                                         end
                                      end

asked 01 May '12, 02:18

jen_ducz's gravatar image

jen_ducz
1334
accept rate: 0%


Every time you loop through all of the cells in a variable, the script is linking each cell with each other cell. You need to restrict the printing to only cells that have matching onsets & offsets, or those that are nested within others.

For example, adding the lines:

if rccell.onset == ccell.onset
if rscell.onset == scell.onset
if rfcell.onset == fcell.onset

This should limit the cells printed. You will likely need to restrict it further, but start there and see if it reduces the number of cells printed.

permanent link

answered 02 Jun '12, 02:07

JohnFranchak's gravatar image

JohnFranchak ♦
3964410
accept rate: 17%

Thanks John! I added the above suggestions to reduce the loops, and it managed to bring it down some. However, I am finding that when I run the script now, it prints each row an extra eight times. I cannot link reliability offset times because they do not always match. Would there be any other areas that might be nested or linked together?

begin control = getVariable("CONTROL") seat = getVariable("SEAT") foam = getVariable("FOAM") rel_control = getVariable("RELCONTROL") rel_seat = getVariable("RELSEAT") rel_foam = getVariable("RELFOAM")

for ccell in control.cells|

for scell in seat.cells

for fcell in foam.cells

                            for rccell in rel_control.cells

                                  for rscell in rel_seat.cells

                                        for rfcell in rel_foam.cells

if rccell.onset.to_s == ccell.onset.to_s if rscell.onset.to_s == scell.onset.to_s if rfcell.onset.to_s == fcell.onset.to_s

                                                                                                   #FINALLY we have everything, so print

print ccell.offset.to_s + "t" + rccell.offset.to_s + "t" + ccell.trialnum + "t" + rccell.trialnum + "t" + scell.side + "t" + rscell.side + "t" + ccell.choice + "t" + rccell.choice + "t" + ccell.sitshift + "t" + rccell.sitshift + "t" + ccell.dirshift + "t" + rccell.dirshift + "t" + ccell.lookoth + "t" + rccell.lookoth + "t" + ccell.reach + "t" + rccell.reach + "t"

Print seat

print scell.offset.to_s + "t" + rscell.offset.to_s + "t" + scell.trialnum + "t" + rscell.trialnum + "t" + scell.side + "t" + rscell.side + "t" + scell.choice + "t" + rscell.choice + "t" + scell.sitshift + "t" + rscell.sitshift + "t" + scell.dirshift + "t" + rscell.dirshift + "t" + scell.lookoth + "t" + rscell.lookoth + "t" + scell.reach + "t" + rscell.reach + "t"

Print foam

print fcell.offset.to_s + "t" + rfcell.offset.to_s + "t" + fcell.trialnum + "t" + rfcell.trialnum + "t" + fcell.side + "t" + rfcell.side + "t" + fcell.choice + "t" + rfcell.choice + "t" + fcell.sitshift + "t" + rfcell.sitshift + "t" + fcell.dirshift + "t" + rfcell.dirshift + "t" + fcell.lookoth + "t" + rfcell.lookoth + "t" + fcell.reach + "t" + rfcell.reach + "n"

                                                 end
                                              end
                                           end
                                        end
                                     end
                                  end

end end end

Thanks again!

permanent link

answered 20 Jun '12, 04:18

jen_ducz's gravatar image

jen_ducz
1334
accept rate: 0%

Is there any reason in particular that you want to print control, seat, and foam all in the same script? I think it's making things overly complicated. If you just get control and rel control and bind them on onsets, it should only print out each pair. However, since you're adding in other variables in your for loops, it's matching each of those pairs with each other. You either need to bind every single variable in a rom by matching all of the onsets, i.e., control onset with rel control onset with foam onset, etc, or just try to limit it to one set of variables.

The best practice for building a new script is to start with something small, test it, and then add on. Try to make the script for just control or just foam and then see if the bindings work.

permanent link

answered 20 Jun '12, 04:33

JohnFranchak's gravatar image

JohnFranchak ♦
3964410
accept rate: 17%

Also, the new post called Printing Comments has a great example of a print script with every bound and limited, you might want to take a look at it as a model.

permanent link

answered 21 Jun '12, 23:30

JohnFranchak's gravatar image

JohnFranchak ♦
3964410
accept rate: 17%

edited 21 Jun '12, 23:31

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×47
×1

question asked: 01 May '12, 02:18

question was seen: 6,236 times

last updated: 21 Jun '12, 23:31

powered by OSQA