Conditional statements with multiple responses


Author
Message
bluebird2020
bluebird2020
New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)
Group: Forum Members
Posts: 3, Visits: 40
Hello,

I'm trying to write a code where two different choices will be displayed either right or left, and each choice will display a different result, where the result is tied to a certain point value. I'm using the counter attribute to randomize the horizontal positions and use the value of the position to write the conditional statements. The participant will answer using the "Z" or "M" keys depending on the position of the choice. For example, if Choice A were 50 points and Choice B were 100 points:

<text z_key>
/ items = ("Z")
/ fontstyle = ("Calibri", 5%, true, false, false, false, 5, 1)
/ position = (30, 40)
</text>

<text m_key>
/ items = ("M")
/ fontstyle = ("Calibri", 5%, true, false, false, false, 5, 1)
/ position = (70, 40)
</text>

<text choice_a>
/ items = ("Choice A")
/ select = replace
/ txcolor = white
/ vposition = 50
/ hposition = values.choiceaposition
/ txbgcolor = gray
</text>

<text choice_b >
/ items = ("Choice B")
/ txcolor = white
/ vposition = 50
/ hposition = values.choicebposition
/ txbgcolor = gray
</text>

<text result>
/ items = ("You chose <% values.result %> points.")
/ position = (50, 30)
</text>

<text total>
/ items = ("You now have <% values.total %> points.")
/ position = (50, 60)
/ erase = false
/ txcolor = aquamarine
</text>

<text continue>
/ items = ("Press the spacebar to continue.")
/ position = (50, 70)
</text>

<text finish>
/ items = ("You earned <% values.total %> points.")
/ position = (50, 50)
/ vjustify = center
/ valign = center
/ halign = center
</text>

** Defaults **

<defaults>
/ fontstyle = ("Calibri", 3.39%, false, false, false, false, 5, 1)
/ txbgcolor = black
/ txcolor = white
/ screencolor = black
/ inputdevice = keyboard
</defaults>

** Values **

<values>
/ result = 0
/ total = 0
/ choiceaposition = 0
/ choicebposition = 0
</values>

** Counter **

<counter choiceposition>
/ items = (30, 70)
/ select = noreplace
/ selectionrate = always
</counter>

** Finish Experiment**

<trial finish>
/ stimulusframes = [1 = finish, exit]
/ validresponse = (exit)
/ recorddata = false
</trial>

**Exit screen**

<button exit>
/ caption = "EXIT"
/ fontstyle = ("Calibri", 2.99%, false, false, false, false, 5, 1)
/ position = (50, 80)
/ size = (20%, 5%)
/ valign = center
/ halign = center
</button>

** Trials **
<trial choice>
/ ontrialbegin = [
  values.result = 0;
  values.choiceaposition = counter.choiceposition.selectedvalue;
  values.choicebposition = counter.choiceposition.selectedvalue;
]
/ stimulusframes= [1 = choice_a, choice_b, z_key, m_key]
/ validresponse = ("z", "m")
/ ontrialend = [
  if (trial.choice.response == "z" && values.choiceaposition == 30) {
   values.result = 50;
   values.total = values.total + values.result;
  } else if (trial.choice.response == "z" && values.choicebposition == 30) {
   values.result = 100;
   values.total = values.total + values.result;
  };
  if (trial.choice.response == "m" && values.choiceaposition == 70) {
   values.result = 50;
   values.total = values.total + values.result;
    } else if (trial.choice.response == "m" && values.choicebposition == 70) {
   values.result = 100;
   values.total = values.total + values.result;
  };
]

/ branch = [
  if (true) {
  return trial.result;  
  }
]
</trial>

<trial result>
/ stimulusframes = [1 = result, continue, total]
/ validresponse = (" ")
/ recorddata = false
</trial>

** Blocks **

<block framing>
/ trials = [1-10 = choice]
</block>

<block finish>
/ trials = [1 = finish]
</block>

** Experiment **

<expt>
/ blocks = [
  1 = framing;
  2 = finish;
]
</expt>

The horizontal position is able to randomize every time. However, every time I run the code, the results always say 0 points earned (and 0 points total). I'm not sure whether the problem is the conditional statement or otherwise? Thank you in advance!





Dave
Dave
Supreme Being (854K reputation)Supreme Being (854K reputation)Supreme Being (854K reputation)Supreme Being (854K reputation)Supreme Being (854K reputation)Supreme Being (854K reputation)Supreme Being (854K reputation)Supreme Being (854K reputation)Supreme Being (854K reputation)
Group: Administrators
Posts: 10K, Visits: 59K
bluebird2020 - 9/10/2020
Hello,

I'm trying to write a code where two different choices will be displayed either right or left, and each choice will display a different result, where the result is tied to a certain point value. I'm using the counter attribute to randomize the horizontal positions and use the value of the position to write the conditional statements. The participant will answer using the "Z" or "M" keys depending on the position of the choice. For example, if Choice A were 50 points and Choice B were 100 points:

<text z_key>
/ items = ("Z")
/ fontstyle = ("Calibri", 5%, true, false, false, false, 5, 1)
/ position = (30, 40)
</text>

<text m_key>
/ items = ("M")
/ fontstyle = ("Calibri", 5%, true, false, false, false, 5, 1)
/ position = (70, 40)
</text>

<text choice_a>
/ items = ("Choice A")
/ select = replace
/ txcolor = white
/ vposition = 50
/ hposition = values.choiceaposition
/ txbgcolor = gray
</text>

<text choice_b >
/ items = ("Choice B")
/ txcolor = white
/ vposition = 50
/ hposition = values.choicebposition
/ txbgcolor = gray
</text>

<text result>
/ items = ("You chose <% values.result %> points.")
/ position = (50, 30)
</text>

<text total>
/ items = ("You now have <% values.total %> points.")
/ position = (50, 60)
/ erase = false
/ txcolor = aquamarine
</text>

<text continue>
/ items = ("Press the spacebar to continue.")
/ position = (50, 70)
</text>

<text finish>
/ items = ("You earned <% values.total %> points.")
/ position = (50, 50)
/ vjustify = center
/ valign = center
/ halign = center
</text>

** Defaults **

<defaults>
/ fontstyle = ("Calibri", 3.39%, false, false, false, false, 5, 1)
/ txbgcolor = black
/ txcolor = white
/ screencolor = black
/ inputdevice = keyboard
</defaults>

** Values **

<values>
/ result = 0
/ total = 0
/ choiceaposition = 0
/ choicebposition = 0
</values>

** Counter **

<counter choiceposition>
/ items = (30, 70)
/ select = noreplace
/ selectionrate = always
</counter>

** Finish Experiment**

<trial finish>
/ stimulusframes = [1 = finish, exit]
/ validresponse = (exit)
/ recorddata = false
</trial>

**Exit screen**

<button exit>
/ caption = "EXIT"
/ fontstyle = ("Calibri", 2.99%, false, false, false, false, 5, 1)
/ position = (50, 80)
/ size = (20%, 5%)
/ valign = center
/ halign = center
</button>

** Trials **
<trial choice>
/ ontrialbegin = [
  values.result = 0;
  values.choiceaposition = counter.choiceposition.selectedvalue;
  values.choicebposition = counter.choiceposition.selectedvalue;
]
/ stimulusframes= [1 = choice_a, choice_b, z_key, m_key]
/ validresponse = ("z", "m")
/ ontrialend = [
  if (trial.choice.response == "z" && values.choiceaposition == 30) {
   values.result = 50;
   values.total = values.total + values.result;
  } else if (trial.choice.response == "z" && values.choicebposition == 30) {
   values.result = 100;
   values.total = values.total + values.result;
  };
  if (trial.choice.response == "m" && values.choiceaposition == 70) {
   values.result = 50;
   values.total = values.total + values.result;
    } else if (trial.choice.response == "m" && values.choicebposition == 70) {
   values.result = 100;
   values.total = values.total + values.result;
  };
]

/ branch = [
  if (true) {
  return trial.result;  
  }
]
</trial>

<trial result>
/ stimulusframes = [1 = result, continue, total]
/ validresponse = (" ")
/ recorddata = false
</trial>

** Blocks **

<block framing>
/ trials = [1-10 = choice]
</block>

<block finish>
/ trials = [1 = finish]
</block>

** Experiment **

<expt>
/ blocks = [
  1 = framing;
  2 = finish;
]
</expt>

The horizontal position is able to randomize every time. However, every time I run the code, the results always say 0 points earned (and 0 points total). I'm not sure whether the problem is the conditional statement or otherwise? Thank you in advance!





The response property

/ ontrialend = [
if (trial.choice.response == "z" && values.choiceaposition == 30) {
 values.result = 50;
 values.total = values.total + values.result;
} else if (trial.choice.response == "z" && values.choicebposition == 30) {
 values.result = 100;
 values.total = values.total + values.result;
};
if (trial.choice.response == "m" && values.choiceaposition == 70) {
 values.result = 50;
 values.total = values.total + values.result;
  } else if (trial.choice.response == "m" && values.choicebposition == 70) {
 values.result = 100;
 values.total = values.total + values.result;
};
]

does not return "z" or "m". It returns the key's numerical scancode. See Tools -> Keyboard Scancodes... in Inquisit Lab or https://www.millisecond.com/support/docs/v6/html/language/scancodes.htm

What you want to use here is the responsetext property, not the response property:

https://www.millisecond.com/support/docs/v6/html/language/properties/responsetext.htm

I.e.

<trial choice>
/ ontrialbegin = [
values.result = 0;
values.choiceaposition = counter.choiceposition.selectedvalue;
values.choicebposition = counter.choiceposition.selectedvalue;
]
/ stimulusframes= [1 = choice_a, choice_b, z_key, m_key]
/ validresponse = ("z", "m")
/ ontrialend = [
if (trial.choice.responsetext == "z" && values.choiceaposition == 30) {
 values.result = 50;
 values.total = values.total + values.result;
} else if (trial.choice.responsetext == "z" && values.choicebposition == 30) {
 values.result = 100;
 values.total = values.total + values.result;
};
if (trial.choice.responsetext == "m" && values.choiceaposition == 70) {
 values.result = 50;
 values.total = values.total + values.result;
  } else if (trial.choice.responsetext == "m" && values.choicebposition == 70) {
 values.result = 100;
 values.total = values.total + values.result;
};
]

/ branch = [
if (true) {
return trial.result;
}
]
</trial>



GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search