PennController for IBEX › Forums › Support › Concatenating variables and text
Tagged: text concatenation, variable
- This topic has 2 replies, 2 voices, and was last updated 2 years, 2 months ago by Jeremy.
-
AuthorPosts
-
September 6, 2022 at 10:43 pm #8397mawilsonParticipant
Following this, I’ve set up my experimment to track participants’ first-guess accuracy in a forced-choice task where they are required to select the correct option before proceeding. This seems to be working perfectly!
However, I would also like to show participants their first-guess accuracy between training blocks if they haven’t done well enough. While I am able to get the text to display, I’m running into a weird bug, where the text after the variable’s value gets pushed to a new line. Here’s what it looks like:
I’d like it to all be on the same line.Here’s the code; following the first link,
responses
stores the first-guess accuracy for each trial, andgrandaverage
is set to the average of that accuracy for each trial.required_to_pass
is a variable currently set to0.5
.newTrial('post-training', newVar('grandaverage') .global() .test.is(v => v >= required_to_pass) .failure( getVar('grandaverage') .set(getVar('responses')) .set(v => v.filter(r => r == true).length/v.length) ) , getVar('grandaverage') .test.is(v => v >= required_to_pass) .success(end()) , newVar('grandaveragepercent') .set(getVar('grandaverage')) .set(v => v * 100) , newVar('responses').global().set([]), newText("Your first-guess accuracy was ") .after( newText() .text(getVar('grandaveragepercent')) ) .after(newText('%.')) .center() .print() , newButton('Next') .center() .print() .wait() )
I’ve also tried adding the
.after(newText('%.'))
to thenewText().text(getVar('grandaveragepercent'))
instead, but I get the same result.- This topic was modified 2 years, 2 months ago by mawilson. Reason: clarifications
September 7, 2022 at 10:28 am #8400mawilsonParticipantI’ve realized how to deal with my case; it’s actually pretty easy since JavaScript lets you use addition to concatenate variables of different types.
newVar('grandaveragepercent') .set(getVar('grandaverage')) .set(v => Math.round(v * 100) + '%.')
Then just display the text as before, minus the
.after(newText('%.'))
.(I’d still be curious how this would work if I had two text variables I wanted to concatenate, since IIRC the way variables work in PCIbex wouldn’t just let you do
getVar('mytextvariable1') + getVar('mytextvariable2')
.)September 19, 2022 at 5:24 pm #8419JeremyKeymasterHi,
I’m glad you found a solution by yourself. You can use
getVar("myvar")._element.value
in a pure-javascript environment to retrieve the current value of the Var element, eg.getVar("mytextvariable1").set( v => v+getVar("mytextvariable2")._element.value )
Jeremy
-
AuthorPosts
- You must be logged in to reply to this topic.