Logging value of randomly chosen text

PennController for IBEX Forums Support Logging value of randomly chosen text

Tagged: ,

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #8288

    Is there a way to log the actual text of a text object? The situation is that I’m randomly choosing 1 of 12 possible words to use for each trial, and I need to log which one is chosen.

    I’ve tried a few things, but most seem to get stuck on the fact that using getX() doesn’t return a value. So setting a number variable and logging it works, but then I can’t use it to get the word. Alternatively, I can directly get the word by string concatenation (as below), but then I can’t log the word that gets chosen (since logging a text object logs the time it was printed but not what the text is).

    Here’s a link to the experiment: https://farm.pcibex.net/r/PtpjPM/

    And here’s a code snippet:

    newText("word", variable["word_" + Math.floor(Math.random() * 12)]).print().log()

    This just logs the print time of the text, but not the actual text.

    The alternative I tried is this:

    newVar("word_num", Math.floor(Math.random() * 12)).log(),
    newText("word", variable["word_" + getVar("word_num")]).print()

    but this doesn’t work because getVar(“word_num”) doesn’t actually return the value.

    What I’d like to do is log ideally the value of the word that gets chosen, but at least log the random number so I can reconstruct that choice later.


    Nevermind; I figured out how to do this. I’ll post it in case anyone else comes across a similar issue.

    Template("practice.csv", variable => {
        var word = variable['word_' + Math.floor(Math.random() * 12)];
        return newTrial("trial_prac",
            // ... whatever else you want here
            newText("word", word)
            // ... whatever else you want here
        ).log("word", word)


    newX commands (and their arguments) are evaluated immediately so even if you were able to directly refer to the value of the Var element (which you can: getVar("word_num").value) you wouldn’t necessarily get what you want, because the execution of a PennController trial (and of the commands on its elements) happens, well, whenever the trial is executed

    You could do this instead:

    newVar("random_word", variable["word_" + Math.floor(Math.random() * 12)] ).log(),
    newText("word", "").text( getVar("random_word") ).print()


    // ...
      word_num = Math.floor(Math.random() * 12),
      newText("word", variable["word_" + word_num]).print()
    .log("word_num", word_num)

    EDIT: sorry, I just saw your second message. That’s a great solution (it’s actually cleaner than creating a variable within newTrial like I suggest)


    • This reply was modified 1 year, 10 months ago by Jeremy.
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.