Millisecond Forums

using expressions to show a Tally for points

https://forums.millisecond.com/Topic29612.aspx

By uni-student92084 - 8/25/2020

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.

<values>
/score =1.00
</values>

**In trial**
/ ontrialend = [values.score = values.score + 0.50 *trial. DemBE_O.correct]
**

<item tally>
/ 1 = "Total score: <% values.score%>"
</item>

<text tally>
/ items = tally
/ hposition = (80)
/ vposition = (20)
</text>

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!

By Dave - 8/25/2020

uni-student92084 - 8/25/2020
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.

<values>
/score =1.00
</values>

**In trial**
/ ontrialend = [values.score = values.score + 0.50 *trial. DemBE_O.correct]
**

<item tally>
/ 1 = "Total score: <% values.score%>"
</item>

<text tally>
/ items = tally
/ hposition = (80)
/ vposition = (20)
</text>

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 <expressions> 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;
    }
]
By uni-student92084 - 8/25/2020

Dave - 8/25/2020
uni-student92084 - 8/25/2020
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.

<values>
/score =1.00
</values>

**In trial**
/ ontrialend = [values.score = values.score + 0.50 *trial. DemBE_O.correct]
**

<item tally>
/ 1 = "Total score: <% values.score%>"
</item>

<text tally>
/ items = tally
/ hposition = (80)
/ vposition = (20)
</text>

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 <expressions> 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?
By Dave - 8/25/2020

uni-student92084 - 8/25/2020
Dave - 8/25/2020
uni-student92084 - 8/25/2020
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.

<values>
/score =1.00
</values>

**In trial**
/ ontrialend = [values.score = values.score + 0.50 *trial. DemBE_O.correct]
**

<item tally>
/ 1 = "Total score: <% values.score%>"
</item>

<text tally>
/ items = tally
/ hposition = (80)
/ vposition = (20)
</text>

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 <expressions> 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