Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Programmatic handling of loop properties and contents in inline_javascript

Hi there,

I'm trying to populate the content of a loop from a memory array (as a method to get around the fact that OSWeb does not handle files as a source in loops). I'm making good progress but I'd need to do a couple of things in an inline_javascript that require accessing built-in variable related to loops:

(1) Is it possible to create columns (and name them) and rows in a loop using inline_javascript code?

(2) Is there a way to retrieve the number of rows from a loop within an inline_javascript object?

I'm interested in finding out what OS built-in variables and object properties can be access using javascript. I found some information about how to interact with these using Python code, but not using Javascript.

Any help or pointers much appreciated! Thanks in advance!

Fabrice.

Buy Me A Coffee

Comments

  • Hi Fabrice,

    Not sure whether this will help, but regarding (1), I think it is not necessary to "rebuild" the loop table in that way. I would just have lists (or arrays) of the information I want to retrieve on every trial and assign them to variables by means of a trial index. Do you know what I mean?

    Regarding (2), well, as there are no rows unless you make them, the number of rows is defined by you. So, if you have your conditions and now how many (unique) trials you have, you can define a variable that carries these information. Alternatively, if you only have a list, you could get the lenght of an array with name_of_array.length (I believe, but better check).

    Eduard

    Buy Me A Coffee

  • Hi @eduard ,

    Thanks for these suggestions!

    I came up with the same idea regarding (1). I'm now using a trial index and got it to work. I had some initial difficulties because for some reason, my code doesn't seem to be populating the loop table unless I create the appropriate number of rows and set up the columns with the variable names:

    In the tests I'm doing at the moment, I set up arrays with data for 48 trials, and have loop with 12 trials that gets repeated 4 times. It works, though I'm not sure why I have to preformat the table instead of leaving it empty as @lvanderlinden did in the experiment published in https://forum.cogsci.nl/discussion/6978/randomly-select-some-trials-from-two-distinct-groups. I suspect it might be because I'm implementing the arrays and handle them in a different way. Anyway, it's working.

    Regarding 2, my practice trials are in a standard table and not populated from an array, so I couldn't use the .length property of an array, but it's not a big deal. I know how many trials are in there (8), and so when running my test loop (from an array), I access the items in the test array by using (vars.count_trial_sequence-8). Accessing the number of rows in the practice table would have just saved me a possible error if I later decide to change the number of practice trials (I'd then have to remember to go change that 8 to whatever new value). Might also implement a bit a Javascript to increment a variable counting the practice trials.

    Thanks for your input!

    Cheers,

    Fabrice.

    Buy Me A Coffee

  • Cool, sounds good!

    If I am not mistaken, the loop tables are actually datamatrix objects. So maybe in those docs, you'll find useful info: https://datamatrix.cogsci.nl/

    Eduard

    Buy Me A Coffee

  • Hi @eduard ,

    Thanks for the tip! Will look it up! 👍️

    Fabrice

    Buy Me A Coffee

Sign In or Register to comment.