Announcing the new Datavyu v1.3.6 with enhanced features and transcription support!

I am attempting to make a script that generates a cell for a variable, that copies the onset time from another variable, but both variables have different arguments. Is there a way in Ruby to make this. I know that if you use a rel-script, it simply copies all of the arguments from the other variable, and transfers them to the new one (over-writing the pre-set arguments for that variable).

For example, I have a variable called "FOOT" that has its own arguments, and another variable called "SIDEPREF" with its own arguments. FOOT and SIDEPREF have the same onset time. So if I was coding FOOT first, would there be a ruby script to generate onset time for SIDEPREF for free, while keeping its own arguments.

Please let me know if this is possible.

asked 28 May '13, 13:49

jducz's gravatar image

jducz
81558
accept rate: 0%


Hello jducz,

It is definitely possible. To do this you want to bring both variables into the script, and loop over the one you want to use as the source of the onsets, and then make a new cell in the other and set the onset. Here is an example using your variable names. Hopefully this will work for you with just minor changes. It should go between the "begin" and "end" commands at the bottom of a script.

# Get the variables that we are going to want to work with
foot = getVariable("FOOT")
sidepref = getVariable("SIDEPREF")

# Now loop over the already coded cells in foot, generating a new cell
# and setting the onset for each cell in sidepref so it is equal to that cell in foot
for footcell in foot.cells
    sidecell = sidepref.make_new_cell()
    sidecell.change_arg("onset", footcell.onset)
end

# Now save sidepref back to the database
setVariable("SIDEPREF", sidepref)

All this script is doing is grabbing the variables from Datavyu and loading them into Ruby, then it loops over each cell that is already coded in foot. For each cell in foot, it creates a new cell in side pref, and then copies the onset from the foot cell into the new sidepref cell. The last command is just saving your changes to sidepref back to the database.

I hope this helps, let me know if this doesn't work for you or you are confused on any point.

permanent link

answered 28 May '13, 14:17

Jesse's gravatar image

Jesse ♦
11181015
accept rate: 53%

This works great! Thanks so much!

(11 Jun '13, 14:56) jducz jducz's gravatar image
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:

×46
×6
×1

question asked: 28 May '13, 13:49

question was seen: 3,074 times

last updated: 11 Jun '13, 14:56

powered by OSQA