the "concat" string function


Author
Message
MattO
MattO
Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)
Group: Forum Members
Posts: 15, Visits: 1

Hi,


Suppose I had this....


/ onblockbegin = [text.sometext = (concat("basket", "ball"))]


Then the text "sometext" would appear as basketball, instead of what it used to be. What I'm wondering is this - Is it possible to use 'concat' to add two 'text' phrases together? Example....


/ onblockbegin = [text.sometext = (concat((sometext), (sometext2)))] =  "sometext + sometext2"?


I know this is invalid syntax, but hopefully you can see what i'm trying to do here.


Basically what i'm trying to do is this - below is a sample script......


<block someblock>
/ trials = [1 = sometrial]
/ bgstim = (sometext)
/ onblockbegin = [text.opentext_p = (concat (sometext + sometext2))]??????
</block>


<text sometext>
/items = someitem
</text>


<item someitem>
/1 = "1. You are about to board a plane. The chance of this plane crashing is "
</item>


<text sometext2>
/items = someitem2
/select = noreplace
</text>

<item someitem2>
/1 = "l_w"
/2 = "lo_"
/3 = "_ow"
</item>


So I have sometext as a background stimulus and I want the end of it to include one randomly generated item from sometext 2's list......eg. it might randomly generate it so that it reads -


1. You are about to board a plane. The chance of this plane crashing is l_w.


then the next time the script is run it might generate it to read -


1. You are about to board a plane. The chance of this plane crashing is lo_.


and so on....


can i use "/onblockbegin = [text.sometext = (concat????" to do this? If not, how might I go about doing this? Hope this makes sense.


Thanks


Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K

You can concatenate anything, including items in <text> elements. However, you should simply do


<item someitem>
/1 = "1. You are about to board a plane. The chance of this plane crashing is <%text.sometext2.currentitem%>"
</item>


MattO
MattO
Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)
Group: Forum Members
Posts: 15, Visits: 1

Thanks Dave that works great. The last thing i need to do is have it so that "sometext2" randomly selects an item from "someitem2", rather than just going with the first item in the list. So far I have the following


<item practice_item>
/1 = "1. You are about to board a plane. The chances of this plane crashing are <%text.sometext2.currentitem%>."
</item>


<text sometext2>
/ items = someitem2
/select = noreplace
</text>


<item someitem2>
/1 = "L_w"
/2 = "Lo_"
/3 = "_ow"
</item>


I was thinking that because I used /select = noreplace that either /1, /2, or/3 would be randomly selected from "someitem2" to add to the end of "someitem". But it still always choses /1 (L_w) to add to the end. How do I make it randomly select from someitem2's list?


thanks


Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K

Selections on a <text> element will only be performed if you actually *use* the respective element in a given <trial> element's /stimulusframes or /stimulustimes:


<block myblock>
/ trials = [1-3=mytrial]
</block>

<trial mytrial>
/ stimulusframes = [1=sometext2,sometext1]
/ validresponse = (57)
</trial>

<text sometext1>
/ items = practice_item
</text>

<item practice_item>
/1 = "1. You are about to board a plane. The chances of this plane crashing are <%text.sometext2.currentitem%>."
</item>

<text sometext2>
/ items = someitem2
/select = noreplace
/ position = (50%, 60%)
</text>

<item someitem2>
/1 = "L_w"
/2 = "Lo_"
/3 = "_ow"
</item>


If you want to keep using <text> elements, you'll want to position <text sometext2> offscreen or give it a /txcolor equal to the screen's background color (so it's invisible). Otherwise, use e.g. a <counter> for which a simple *reference* will suffice to execute a selection:


<block myblock>
/ trials = [1-3=mytrial]
</block>

<trial mytrial>
/ stimulusframes = [1=sometext1]
/ validresponse = (57)
</trial>

<text sometext1>
/ items = practice_item
</text>

<item practice_item>
/1 = "1. You are about to board a plane. The chances of this plane crashing are <%counter.sometext2.selectedvalue%>."
</item>

<counter sometext2>
/ items = ("L_w", "Lo_", "_ow")
/select = noreplace
</counter>


Regards,


~Dave


MattO
MattO
Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)Partner Member (821 reputation)
Group: Forum Members
Posts: 15, Visits: 1

Thanks dave, that's perfect!


leluxe
leluxe
Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)
Group: Forum Members
Posts: 18, Visits: 85
Hi Dave,
I have a brief question:

I want to concatenate the answer string of an openended element with the letters "DONE" and then have this new concatenated string written in my data file. Could you help me out by telling me the correct syntax for this?
I tried the following approaches:

<text VPtext>
/items = ("bla")
/position = (50,40)
</text>

<openended VP>
/ stimulusframes = [1=VPtext]
/ position = (50, 55)
/ linelength = 20
/ numlines = 1
/ mouse = true
/ inputdevice = keyboard
/ buttonlabel = "OK"
/ ontrialend = [concat(openended.vp.response,"DONE")]
</openended>

or:
<openended VP>
/ stimulusframes = [1=VPtext]
/ position = (50, 55)
/ linelength = 20
/ numlines = 1
/ mouse = true
/ inputdevice = keyboard
/ buttonlabel = "OK"
/ ontrialend = [openended.vp.response =(concat(openended.vp.response,"DONE"))]
</openended>
=> got a "this is read-only content" error, well I coud have imagined that

furthermore I tried to set an external value:
<values>
/ vpcode = concat(openended.vp.response,"DONE")
</values>

But somehow the strings never concatenate. It's always the response only in the column for the response and always only "DONE" in the column for the value.

Would greatly appreciate if you could help me out here.

Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
> I want to concatenate the answer string of an openended element with the letters "DONE" and then have this new concatenated string
> written in my data file.

The correct way to do this is

<values>
/ oe_response = ""
</values>

<openended VP>
...
/ ontrialend = [values.oe_response = concat(openended.vp.response,"DONE")]
</openended>

with

<data>
/ columns = [... values.oe_response ...]
...
</data>

leluxe
leluxe
Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)
Group: Forum Members
Posts: 18, Visits: 85
This worked out and I got why.
Thank you very much, Dave.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search