Conditional branching


Author
Message
Nick Riches
Nick Riches
Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)
Group: Forum Members
Posts: 19, Visits: 69
Hi. I am trying to get a conditional branch to work. 3 sentences are presented. For only some of the sentences there is a comprehension question. I've tried to achieve this using a conditional statement so that the question trial is triggered only when the question item is not an empty string (/ branch = [if(text.question != "")trial.questionTrial]). However, the question trial is triggered all the time.

Is there a problem with my conditional statement?

Thanks

Nick




<item sentences>
/ 1 = "A dog is a canine"
/ 2 = "A cat is a feline"
/ 3 = "A bear is ursine"
</item>

<item questions>
/ 1 = ""
/ 2 = "Did this sentence mention a cat?"
/ 3 = ""
</item>

<text sentence>
/ items = sentences
/ select = sequence
</text>

<text question>
/ items = questions
/ select = text.sentence.currentindex
</text>

<trial sentenceTrial>
/ stimulusframes = [1 = sentence]
/ validresponse = ("Y", "N")
/ branch = [if(text.question != "")trial.questionTrial]
</trial>

<trial questionTrial>
/ stimulusframes = [1 = question]
/ validresponse = ("Y", "N")
</trial>

<block block>
/ trials = [1-3 = sentenceTrial]
</block>

<expt expt>
/ blocks = [1 = block]
</expt>


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: 105K
Nick Riches - Tuesday, November 21, 2017
Hi. I am trying to get a conditional branch to work. 3 sentences are presented. For only some of the sentences there is a comprehension question. I've tried to achieve this using a conditional statement so that the question trial is triggered only when the question item is not an empty string (/ branch = [if(text.question != "")trial.questionTrial]). However, the question trial is triggered all the time.

Is there a problem with my conditional statement?

Thanks

Nick




<item sentences>
/ 1 = "A dog is a canine"
/ 2 = "A cat is a feline"
/ 3 = "A bear is ursine"
</item>

<item questions>
/ 1 = ""
/ 2 = "Did this sentence mention a cat?"
/ 3 = ""
</item>

<text sentence>
/ items = sentences
/ select = sequence
</text>

<text question>
/ items = questions
/ select = text.sentence.currentindex
</text>

<trial sentenceTrial>
/ stimulusframes = [1 = sentence]
/ validresponse = ("Y", "N")
/ branch = [if(text.question != "")trial.questionTrial]
</trial>

<trial questionTrial>
/ stimulusframes = [1 = question]
/ validresponse = ("Y", "N")
</trial>

<block block>
/ trials = [1-3 = sentenceTrial]
</block>

<expt expt>
/ blocks = [1 = block]
</expt>


Sorry, this setup doesn't seem to make sense. First off.

text.question doesn't return anything -- you're not accessing or reading any of the text element's properties.

Moreover, <text question> is only used in <trial questiontrial>, which is the trial you wish to /branch to. How is <trial sentence> supposed to know about things that only happen later, in <trial questiontrial> and behave accordingly?

What you can do to get this to work is:

<item sentences>
/ 1 = "A dog is a canine"
/ 2 = "A cat is a feline"
/ 3 = "A bear is ursine"
</item>

<item questions>
/ 1 = ""
/ 2 = "Did this sentence mention a cat?"
/ 3 = ""
</item>

<text sentence>
/ items = sentences
/ select = sequence
</text>

<text question>
/ items = questions
/ select = text.sentence.currentindex
</text>

<trial sentenceTrial>
/ ontrialbegin = [
    text.question.hposition = -10%;
    text.question.vposition = -10%;
]
/ stimulusframes = [1 = sentence, question]
/ validresponse = ("Y", "N")
/ branch = [if(text.question.currentitem != "")trial.questionTrial]
</trial>

<trial questionTrial>
/ ontrialbegin = [
    text.question.hposition = 50%;
    text.question.vposition = 50%;
]
/ stimulusframes = [1 = question]
/ validresponse = ("Y", "N")
</trial>

<block block>
/ trials = [1-3 = sentenceTrial]
</block>

<expt expt>
/ blocks = [1 = block]
</expt>


Edited 8 Years Ago by Dave
Nick Riches
Nick Riches
Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)
Group: Forum Members
Posts: 19, Visits: 69
Dave - Tuesday, November 21, 2017
Nick Riches - Tuesday, November 21, 2017
Hi. I am trying to get a conditional branch to work. 3 sentences are presented. For only some of the sentences there is a comprehension question. I've tried to achieve this using a conditional statement so that the question trial is triggered only when the question item is not an empty string (/ branch = [if(text.question != "")trial.questionTrial]). However, the question trial is triggered all the time.

Is there a problem with my conditional statement?

Thanks

Nick




<item sentences>
/ 1 = "A dog is a canine"
/ 2 = "A cat is a feline"
/ 3 = "A bear is ursine"
</item>

<item questions>
/ 1 = ""
/ 2 = "Did this sentence mention a cat?"
/ 3 = ""
</item>

<text sentence>
/ items = sentences
/ select = sequence
</text>

<text question>
/ items = questions
/ select = text.sentence.currentindex
</text>

<trial sentenceTrial>
/ stimulusframes = [1 = sentence]
/ validresponse = ("Y", "N")
/ branch = [if(text.question != "")trial.questionTrial]
</trial>

<trial questionTrial>
/ stimulusframes = [1 = question]
/ validresponse = ("Y", "N")
</trial>

<block block>
/ trials = [1-3 = sentenceTrial]
</block>

<expt expt>
/ blocks = [1 = block]
</expt>


Sorry, this setup doesn't seem to make sense. First off.

text.question doesn't return anything -- you're not accessing or reading any of the text element's properties.

Moreover, <text question> is only used in <trial questiontrial>, which is the trial you wish to /branch to. How is <trial sentence> supposed to know about things that only happen later, in <trial questiontrial> and behave accordingly?

What you can do to get this to work is:

<item sentences>
/ 1 = "A dog is a canine"
/ 2 = "A cat is a feline"
/ 3 = "A bear is ursine"
</item>

<item questions>
/ 1 = ""
/ 2 = "Did this sentence mention a cat?"
/ 3 = ""
</item>

<text sentence>
/ items = sentences
/ select = sequence
</text>

<text question>
/ items = questions
/ select = text.sentence.currentindex
</text>

<trial sentenceTrial>
/ ontrialbegin = [
    text.question.hposition = -10%;
    text.question.vposition = -10%;
]
/ stimulusframes = [1 = sentence, question]
/ validresponse = ("Y", "N")
/ branch = [if(text.question.currentitem != "")trial.questionTrial]
</trial>

<trial questionTrial>
/ ontrialbegin = [
    text.question.hposition = 50%;
    text.question.vposition = 50%;
]
/ stimulusframes = [1 = question]
/ validresponse = ("Y", "N")
</trial>

<block block>
/ trials = [1-3 = sentenceTrial]
</block>

<expt expt>
/ blocks = [1 = block]
</expt>


Many thanks. That does the trick.

I'm still a bit confused why 'text.question' doesn't work in my example. This object has been defined. I presume one needs to reference it somewhere in the trial object, in order for it to be 'instantiated' as a trial which can then be referred to in the conditional statement? You've referred to it in the 'ontrialbegin' property, which appears to set the position of the text off-screen. I presume this allows one to link to the trial in the conditional statement. If this were a sound file, or image file, I presume I would need to find a different way to reference it?

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: 105K
Nick Riches - Wednesday, November 22, 2017
Dave - Tuesday, November 21, 2017
Nick Riches - Tuesday, November 21, 2017
Hi. I am trying to get a conditional branch to work. 3 sentences are presented. For only some of the sentences there is a comprehension question. I've tried to achieve this using a conditional statement so that the question trial is triggered only when the question item is not an empty string (/ branch = [if(text.question != "")trial.questionTrial]). However, the question trial is triggered all the time.

Is there a problem with my conditional statement?

Thanks

Nick




<item sentences>
/ 1 = "A dog is a canine"
/ 2 = "A cat is a feline"
/ 3 = "A bear is ursine"
</item>

<item questions>
/ 1 = ""
/ 2 = "Did this sentence mention a cat?"
/ 3 = ""
</item>

<text sentence>
/ items = sentences
/ select = sequence
</text>

<text question>
/ items = questions
/ select = text.sentence.currentindex
</text>

<trial sentenceTrial>
/ stimulusframes = [1 = sentence]
/ validresponse = ("Y", "N")
/ branch = [if(text.question != "")trial.questionTrial]
</trial>

<trial questionTrial>
/ stimulusframes = [1 = question]
/ validresponse = ("Y", "N")
</trial>

<block block>
/ trials = [1-3 = sentenceTrial]
</block>

<expt expt>
/ blocks = [1 = block]
</expt>


Sorry, this setup doesn't seem to make sense. First off.

text.question doesn't return anything -- you're not accessing or reading any of the text element's properties.

Moreover, <text question> is only used in <trial questiontrial>, which is the trial you wish to /branch to. How is <trial sentence> supposed to know about things that only happen later, in <trial questiontrial> and behave accordingly?

What you can do to get this to work is:

<item sentences>
/ 1 = "A dog is a canine"
/ 2 = "A cat is a feline"
/ 3 = "A bear is ursine"
</item>

<item questions>
/ 1 = ""
/ 2 = "Did this sentence mention a cat?"
/ 3 = ""
</item>

<text sentence>
/ items = sentences
/ select = sequence
</text>

<text question>
/ items = questions
/ select = text.sentence.currentindex
</text>

<trial sentenceTrial>
/ ontrialbegin = [
    text.question.hposition = -10%;
    text.question.vposition = -10%;
]
/ stimulusframes = [1 = sentence, question]
/ validresponse = ("Y", "N")
/ branch = [if(text.question.currentitem != "")trial.questionTrial]
</trial>

<trial questionTrial>
/ ontrialbegin = [
    text.question.hposition = 50%;
    text.question.vposition = 50%;
]
/ stimulusframes = [1 = question]
/ validresponse = ("Y", "N")
</trial>

<block block>
/ trials = [1-3 = sentenceTrial]
</block>

<expt expt>
/ blocks = [1 = block]
</expt>


Many thanks. That does the trick.

I'm still a bit confused why 'text.question' doesn't work in my example. This object has been defined. I presume one needs to reference it somewhere in the trial object, in order for it to be 'instantiated' as a trial which can then be referred to in the conditional statement? You've referred to it in the 'ontrialbegin' property, which appears to set the position of the text off-screen. I presume this allows one to link to the trial in the conditional statement. If this were a sound file, or image file, I presume I would need to find a different way to reference it?

> I'm still a bit confused why 'text.question' doesn't work in my example.

text.question just references the <text> object called "question". text.question by itself does or says nothing: Which of the dozens pieces of information available about the object is it supposed to convey?
A text object has many different properties, like its current item, its position, its size, its color, and so forth, so you need to specify _which_ piece of information (property) you wish to know about. If you want to know the currently selected item of the text object, you access the currentitem property

text.question.currentitem

Note that the object only selects an item once it is _actually_ used / displayed by a trial. If you want to know or change the text object's horizontal position, you access its hposition property

text.question.hposition

and so forth.

> I presume one needs to reference it somewhere in the trial object, in order for it to be 'instantiated' as a trial which can then be referred to in the conditional statement?

No, that's not exactly right. As a general rule, a stimulus object only performs item selection once it is actually _displayed_ via a <trial>'s /stimulustimes or -frames.

> If this were a sound file, or image file, I presume I would need to find a different way to reference it?

Not necessarily. A <picture> object can be moved off-screen just as well. A <sound> object could be muted. But generally, the approach you used is not ideal and I'd rather do something like this:

<item sentences>
/ 1 = "A dog is a canine"
/ 2 = "A cat is a feline"
/ 3 = "A bear is ursine"
</item>

<list has_followup>
/ items = (false, true, false)
/ selectionmode = text.sentence.currentindex
</list>


<item questions>
/ 1 = ""
/ 2 = "Did this sentence mention a cat?"
/ 3 = ""
</item>

<text sentence>
/ items = sentences
/ select = sequence
</text>

<text question>
/ items = questions
/ select = text.sentence.currentindex
</text>

<trial sentenceTrial>
/ stimulusframes = [1 = sentence]
/ validresponse = ("Y", "N")
/ branch = [if(list.has_followup.nextvalue)trial.questionTrial]
</trial>

<trial questionTrial>
/ stimulusframes = [1 = question]
/ validresponse = ("Y", "N")
</trial>

<block block>
/ trials = [1-3 = sentenceTrial]
</block>

<expt expt>
/ blocks = [1 = block]
</expt>


Nick Riches
Nick Riches
Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)Esteemed Member (2K reputation)
Group: Forum Members
Posts: 19, Visits: 69
Dave - Wednesday, November 22, 2017
Nick Riches - Wednesday, November 22, 2017
Dave - Tuesday, November 21, 2017
Nick Riches - Tuesday, November 21, 2017
Hi. I am trying to get a conditional branch to work. 3 sentences are presented. For only some of the sentences there is a comprehension question. I've tried to achieve this using a conditional statement so that the question trial is triggered only when the question item is not an empty string (/ branch = [if(text.question != "")trial.questionTrial]). However, the question trial is triggered all the time.

Is there a problem with my conditional statement?

Thanks

Nick




<item sentences>
/ 1 = "A dog is a canine"
/ 2 = "A cat is a feline"
/ 3 = "A bear is ursine"
</item>

<item questions>
/ 1 = ""
/ 2 = "Did this sentence mention a cat?"
/ 3 = ""
</item>

<text sentence>
/ items = sentences
/ select = sequence
</text>

<text question>
/ items = questions
/ select = text.sentence.currentindex
</text>

<trial sentenceTrial>
/ stimulusframes = [1 = sentence]
/ validresponse = ("Y", "N")
/ branch = [if(text.question != "")trial.questionTrial]
</trial>

<trial questionTrial>
/ stimulusframes = [1 = question]
/ validresponse = ("Y", "N")
</trial>

<block block>
/ trials = [1-3 = sentenceTrial]
</block>

<expt expt>
/ blocks = [1 = block]
</expt>


Sorry, this setup doesn't seem to make sense. First off.

text.question doesn't return anything -- you're not accessing or reading any of the text element's properties.

Moreover, <text question> is only used in <trial questiontrial>, which is the trial you wish to /branch to. How is <trial sentence> supposed to know about things that only happen later, in <trial questiontrial> and behave accordingly?

What you can do to get this to work is:

<item sentences>
/ 1 = "A dog is a canine"
/ 2 = "A cat is a feline"
/ 3 = "A bear is ursine"
</item>

<item questions>
/ 1 = ""
/ 2 = "Did this sentence mention a cat?"
/ 3 = ""
</item>

<text sentence>
/ items = sentences
/ select = sequence
</text>

<text question>
/ items = questions
/ select = text.sentence.currentindex
</text>

<trial sentenceTrial>
/ ontrialbegin = [
    text.question.hposition = -10%;
    text.question.vposition = -10%;
]
/ stimulusframes = [1 = sentence, question]
/ validresponse = ("Y", "N")
/ branch = [if(text.question.currentitem != "")trial.questionTrial]
</trial>

<trial questionTrial>
/ ontrialbegin = [
    text.question.hposition = 50%;
    text.question.vposition = 50%;
]
/ stimulusframes = [1 = question]
/ validresponse = ("Y", "N")
</trial>

<block block>
/ trials = [1-3 = sentenceTrial]
</block>

<expt expt>
/ blocks = [1 = block]
</expt>


Many thanks. That does the trick.

I'm still a bit confused why 'text.question' doesn't work in my example. This object has been defined. I presume one needs to reference it somewhere in the trial object, in order for it to be 'instantiated' as a trial which can then be referred to in the conditional statement? You've referred to it in the 'ontrialbegin' property, which appears to set the position of the text off-screen. I presume this allows one to link to the trial in the conditional statement. If this were a sound file, or image file, I presume I would need to find a different way to reference it?

> I'm still a bit confused why 'text.question' doesn't work in my example.

text.question just references the <text> object called "question". text.question by itself does or says nothing: Which of the dozens pieces of information available about the object is it supposed to convey?
A text object has many different properties, like its current item, its position, its size, its color, and so forth, so you need to specify _which_ piece of information (property) you wish to know about. If you want to know the currently selected item of the text object, you access the currentitem property

text.question.currentitem

Note that the object only selects an item once it is _actually_ used / displayed by a trial. If you want to know or change the text object's horizontal position, you access its hposition property

text.question.hposition

and so forth.

> I presume one needs to reference it somewhere in the trial object, in order for it to be 'instantiated' as a trial which can then be referred to in the conditional statement?

No, that's not exactly right. As a general rule, a stimulus object only performs item selection once it is actually _displayed_ via a <trial>'s /stimulustimes or -frames.

> If this were a sound file, or image file, I presume I would need to find a different way to reference it?

Not necessarily. A <picture> object can be moved off-screen just as well. A <sound> object could be muted. But generally, the approach you used is not ideal and I'd rather do something like this:

<item sentences>
/ 1 = "A dog is a canine"
/ 2 = "A cat is a feline"
/ 3 = "A bear is ursine"
</item>

<list has_followup>
/ items = (false, true, false)
/ selectionmode = text.sentence.currentindex
</list>


<item questions>
/ 1 = ""
/ 2 = "Did this sentence mention a cat?"
/ 3 = ""
</item>

<text sentence>
/ items = sentences
/ select = sequence
</text>

<text question>
/ items = questions
/ select = text.sentence.currentindex
</text>

<trial sentenceTrial>
/ stimulusframes = [1 = sentence]
/ validresponse = ("Y", "N")
/ branch = [if(list.has_followup.nextvalue)trial.questionTrial]
</trial>

<trial questionTrial>
/ stimulusframes = [1 = question]
/ validresponse = ("Y", "N")
</trial>

<block block>
/ trials = [1-3 = sentenceTrial]
</block>

<expt expt>
/ blocks = [1 = block]
</expt>


That's really incredibly useful, and the 'list' method looks like a much better way to do this. Thanks so much for this.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search