PennController for IBEX › Forums › Support › Concatenating variables and text
Tagged: text concatenation, variable
- This topic has 2 replies, 2 voices, and was last updated 8 months, 2 weeks ago by Jeremy.
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,
responsesstores the first-guess accuracy for each trial, and
grandaverageis set to the average of that accuracy for each trial.
required_to_passis a variable currently set to
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
newText().text(getVar('grandaveragepercent'))instead, but I get the same result.
September 7, 2022 at 10:28 am #8400mawilsonParticipant
- This topic was modified 9 months ago by mawilson. Reason: clarifications
newVar('grandaveragepercent') .set(getVar('grandaverage')) .set(v => Math.round(v * 100) + '%.')
Then just display the text as before, minus the
(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 #8419JeremyKeymaster
I’m glad you found a solution by yourself. You can use
getVar("mytextvariable1").set( v => v+getVar("mytextvariable2")._element.value )
- You must be logged in to reply to this topic.