## using expressions to show a Tally for points

##### using expressions to show a Tally for points
 Author Message uni-student92084          Group: Forum Members Posts: 50, Visits: 137 Hello, In my script, particpants will be rewarded 5 cents if they are correct and lose 5 cents if they are incorrect. My goal is to show the particpants a tally of the total amount of money they have earned on each trial. With the code I have tried so far (shown below), the total monetary reward shows up and they gain 5 cents when they are correct, but instead of losing 5 cents when they are wrong, their amount stays the same./score =1.00**In trial**/ ontrialend = [values.score = values.score + 0.50 *trial. DemBE_O.correct] **/ 1 = "Total score: <% values.score%>"/ items = tally/ hposition = (80)/ vposition = (20)I realize that in /ontrialend=, it make sense for them to not lose points because 0.50 is multiplied by 0. But if I wanted the tally of money to decrease by 5 cents, how would I do this? I am pretty sure I would have to use the expression element and maybe the if, else statments, but I am having trouble figuring out how to format it. I will also attach the full script for more context.Thank you in advance for your help! Attachments try with expressions.iqx (10 views, 269.00 KB) Dave posted Last Month ANSWER         Group: Administrators Posts: 10K, Visits: 59K +x uni-student92084 - 8/25/2020Hello, In my script, particpants will be rewarded 5 cents if they are correct and lose 5 cents if they are incorrect. My goal is to show the particpants a tally of the total amount of money they have earned on each trial. With the code I have tried so far (shown below), the total monetary reward shows up and they gain 5 cents when they are correct, but instead of losing 5 cents when they are wrong, their amount stays the same./score =1.00**In trial**/ ontrialend = [values.score = values.score + 0.50 *trial. DemBE_O.correct] **/ 1 = "Total score: <% values.score%>"/ items = tally/ hposition = (80)/ vposition = (20)I realize that in /ontrialend=, it make sense for them to not lose points because 0.50 is multiplied by 0. But if I wanted the tally of money to decrease by 5 cents, how would I do this? I am pretty sure I would have to use the expression element and maybe the if, else statments, but I am having trouble figuring out how to format it. I will also attach the full script for more context.Thank you in advance for your help!You don't need the element, all you need is a few simple if conditions in your /ontrialend logic./ ontrialend = [    if (trial.DemBI_P.correct) {        values.score += 0.50;    } else if (trial.DemBI_P.error) {        values.score -= 0.50;    }] uni-student92084          Group: Forum Members Posts: 50, Visits: 137 +x Dave - 8/25/2020+x uni-student92084 - 8/25/2020Hello, In my script, particpants will be rewarded 5 cents if they are correct and lose 5 cents if they are incorrect. My goal is to show the particpants a tally of the total amount of money they have earned on each trial. With the code I have tried so far (shown below), the total monetary reward shows up and they gain 5 cents when they are correct, but instead of losing 5 cents when they are wrong, their amount stays the same./score =1.00**In trial**/ ontrialend = [values.score = values.score + 0.50 *trial. DemBE_O.correct] **/ 1 = "Total score: <% values.score%>"/ items = tally/ hposition = (80)/ vposition = (20)I realize that in /ontrialend=, it make sense for them to not lose points because 0.50 is multiplied by 0. But if I wanted the tally of money to decrease by 5 cents, how would I do this? I am pretty sure I would have to use the expression element and maybe the if, else statments, but I am having trouble figuring out how to format it. I will also attach the full script for more context.Thank you in advance for your help!You don't need the element, all you need is a few simple if conditions in your /ontrialend logic./ ontrialend = [    if (trial.DemBI_P.correct) {        values.score += 0.50;    } else if (trial.DemBI_P.error) {        values.score -= 0.50;    }]That makes sense, thank you Dave! One question, what do the symbols += and -= mean? I am guessing they mean add and subtract from value.score, right? Dave posted Last Month ANSWER         Group: Administrators Posts: 10K, Visits: 59K +x uni-student92084 - 8/25/2020+x Dave - 8/25/2020+x uni-student92084 - 8/25/2020Hello, In my script, particpants will be rewarded 5 cents if they are correct and lose 5 cents if they are incorrect. My goal is to show the particpants a tally of the total amount of money they have earned on each trial. With the code I have tried so far (shown below), the total monetary reward shows up and they gain 5 cents when they are correct, but instead of losing 5 cents when they are wrong, their amount stays the same./score =1.00**In trial**/ ontrialend = [values.score = values.score + 0.50 *trial. DemBE_O.correct] **/ 1 = "Total score: <% values.score%>"/ items = tally/ hposition = (80)/ vposition = (20)I realize that in /ontrialend=, it make sense for them to not lose points because 0.50 is multiplied by 0. But if I wanted the tally of money to decrease by 5 cents, how would I do this? I am pretty sure I would have to use the expression element and maybe the if, else statments, but I am having trouble figuring out how to format it. I will also attach the full script for more context.Thank you in advance for your help!You don't need the element, all you need is a few simple if conditions in your /ontrialend logic./ ontrialend = [    if (trial.DemBI_P.correct) {        values.score += 0.50;    } else if (trial.DemBI_P.error) {        values.score -= 0.50;    }]That makes sense, thank you Dave! One question, what do the symbols += and -= mean? I am guessing they mean add and subtract from value.score, right?Correct.They're the increment and decrement operators: https://www.millisecond.com/support/docs/v6/html/language/expressions/operators.htm

#### Merge Selected

Merge into selected topic...

Merge into merge target...

Merge into a specific topic ID...