Reply To: Logging value of randomly chosen text

PennController for IBEX Forums Support Logging value of randomly chosen text Reply To: Logging value of randomly chosen text

#8290
Jeremy
Keymaster

Hi,

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()

or

newTrial("trial_prac",
// ...
  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)

Jeremy

  • This reply was modified 1 year, 9 months ago by Jeremy.