Cyberball 5 Keyboard Control Issue - Urgent Help Needed


Author
Message
periperiperika555
periperiperika555
Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)
Group: Forum Members
Posts: 5, Visits: 11
Hello,

I hope this message finds you well. We are currently working on a research project at our university involving "Cyberball 5," and we are looking to create three Cyberball tasks for this study.

To use fMRI in our research, we need to transition from mouse-click-based controls to keyboard controls entirely. However, we have encountered an issue when setting "validresponse=("4","9")" and "inputdevice=keyboard" in the "trial" section. It seems that when Player 2 throws the ball, it goes in the opposite direction and does not function correctly. (We want to configure it so that pressing the 4 key throws to Player 1, and pressing the 9 key throws to Player 3.)

By the way, when we set the key for throwing to Player 3 as "validresponse=("E","I")," the ball is thrown correctly only to Player 3, and it works as expected. Any key other than "I" does not work correctly.

Currently, the program looks like this:

<trial npctrial>
/ ontrialbegin = [
    values.received_from = values.ball_at;
    values.ball_at = values.throw_to;
    if (values.ball_at == 2) {
        values.player2received += 1;
    };
    expressions.set_offsets;
    
    values.player1state = (values.ball_at == 1) + 1;
    values.player2state = (values.ball_at == 2) + 1;
    values.player3state = (values.ball_at == 3) + 1;
    values.player4state = (values.ball_at == 4) + 1;
    values.player5state = (values.ball_at == 5) + 1;
    values.player6state = (values.ball_at == 6) + 1;
    values.player7state = (values.ball_at == 7) + 1;
    values.player8state = (values.ball_at == 8) + 1;
    values.player9state = (values.ball_at == 9) + 1;
    
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    if (values.throw_to == 0){
    values.throw_to = list.npcs.nextindex;
    values.delay = round(rand(1, 4)) * 1000;
    };
    while (values.throw_to == values.ball_at){
        values.deprecated +=1;
        values.throw_to = list.throwschedule.nextvalue;
        values.delay = list.delayschedule.nextvalue;
    };
]

/ ontrialend = [
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.throwcount += 1;
    if (values.ball_at == 2) {
        values.player2thrown += 1;
    };
]

/ stimulusframes = [1=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    stats]

/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = values.delay
/ branch = [
    return trial.throw;
]
</trial>

// handles the human player
<trial player2>
/ ontrialbegin = [
    values.received_from = values.ball_at;
    expressions.set_offsets;
    
    values.player2received += 1;
    
    values.player1state = 1;
    //catch
    values.player2state = 2;
    values.player3state = 1;
    values.player4state = 1;
    values.player5state = 1;
    values.player6state = 1;
    values.player7state = 1;
    values.player8state = 1;
    values.player9state = 1;
    
    values.ball_at = 2;
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    
]

/ ontrialend = [
    values.throw_to = substring(trial.player2.response, length(trial.player2.response)-1, 1);
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.player2thrown += 1;
    values.throwcount += 1;
]

/ stimulusframes = [1=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    stats]

/ validresponse = ("4", "9", player4, player5, player6, player7, player8, player9)
/ responsemessage = ("4", player1click, 100)
/ responsemessage = ("9", player3click, 100)
/ responsemessage = (player4, player4click, 100)
/ responsemessage = (player5, player5click, 100)
/ responsemessage = (player6, player6click, 100)
/ responsemessage = (player7, player7click, 100)
/ responsemessage = (player8, player8click, 100)
/ responsemessage = (player9, player9click, 100)
/ inputdevice = keyboard
/ branch = [
 if (trial.player2.response == 5) 
values.throw_to == 1
 return trial.throw;
]
/ branch = [
  if (trial.player2.response == 10) /
    values.throw_to == 3
    return trial.throw;
]
</trial>

// implements the throw animation
<trial throw>
/ ontrialbegin = [
    picture.player1.skip = expressions.skip_player1pic;
    picture.player2.skip = expressions.skip_player2pic;
    picture.player3.skip = expressions.skip_player3pic;
    picture.player4.skip = expressions.skip_player4pic;
    picture.player5.skip = expressions.skip_player5pic;
    picture.player6.skip = expressions.skip_player6pic;
    picture.player7.skip = expressions.skip_player7pic;
    picture.player8.skip = expressions.skip_player8pic;
    picture.player9.skip = expressions.skip_player9pic;
    
    values.throwingplayer_x = list.player_x.item(values.ball_at);
    values.throwingplayer_y = list.player_y.item(values.ball_at);
    values.receivingplayer_x = list.player_x.item(values.throw_to);
    values.receivingplayer_y = list.player_y.item(values.throw_to);
    values.ball_x = values.receivingplayer_x;
    expressions.set_throwoffset;
]

/ ontrialend = [
    if (values.throwcount >= parameters.nthrows){
        values.stop = true;
    } else {
        values.stop = false;
    };
    picture.player1.skip = false;
    picture.player2.skip = false;
    picture.player3.skip = false;
    picture.player4.skip = false;
    picture.player5.skip = false;
    picture.player6.skip = false;
    picture.player7.skip = false;
    picture.player8.skip = false;
    picture.player9.skip = false;
]

/ stimulustimes = [0=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow0, stats;
    
    500=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow1, stats;
    
    600=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow2, stats;
    
    700=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow3, stats;
    
    800=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow4, stats;
    
    900=ball_to]
    
/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = 900 + expressions.throwduration
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// displays the welcome message / instructions / game cover story
<trial instructions>
/ stimulusframes = [1=clearscreen, banner, logo, instructions, play]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

<trial instructions2>
/ stimulusframes = [1=getReady]
/ trialduration = parameters.readyDuration
/ beginresponsetime = parameters.readyDuration
/ recorddata = false
</trial>

// displays the "Connecting to other players..." message and animation
<trial start>
/ ontrialbegin = [
    list.npcs.reset();
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.ball_x = list.player_x.item(values.throw_to);
]
/ stimulusframes = [1=clearscreen, connectingmessage, connectinganimation]
/ inputdevice = keyboard
/ validresponse = (0)
/ trialduration = replace(5000,6000,7000)
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// end screen with exit button
<trial thankyou>
/ stimulusframes = [1=clearscreen, thankyoumessage, exit]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>


We are running out of time and are in quite a predicament. Any help you can provide would be greatly appreciated. Thank you in advance.
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
periperiperika555 - 9/30/2023
Hello,

I hope this message finds you well. We are currently working on a research project at our university involving "Cyberball 5," and we are looking to create three Cyberball tasks for this study.

To use fMRI in our research, we need to transition from mouse-click-based controls to keyboard controls entirely. However, we have encountered an issue when setting "validresponse=("4","9")" and "inputdevice=keyboard" in the "trial" section. It seems that when Player 2 throws the ball, it goes in the opposite direction and does not function correctly. (We want to configure it so that pressing the 4 key throws to Player 1, and pressing the 9 key throws to Player 3.)

By the way, when we set the key for throwing to Player 3 as "validresponse=("E","I")," the ball is thrown correctly only to Player 3, and it works as expected. Any key other than "I" does not work correctly.

Currently, the program looks like this:

<trial npctrial>
/ ontrialbegin = [
    values.received_from = values.ball_at;
    values.ball_at = values.throw_to;
    if (values.ball_at == 2) {
        values.player2received += 1;
    };
    expressions.set_offsets;
    
    values.player1state = (values.ball_at == 1) + 1;
    values.player2state = (values.ball_at == 2) + 1;
    values.player3state = (values.ball_at == 3) + 1;
    values.player4state = (values.ball_at == 4) + 1;
    values.player5state = (values.ball_at == 5) + 1;
    values.player6state = (values.ball_at == 6) + 1;
    values.player7state = (values.ball_at == 7) + 1;
    values.player8state = (values.ball_at == 8) + 1;
    values.player9state = (values.ball_at == 9) + 1;
    
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    if (values.throw_to == 0){
    values.throw_to = list.npcs.nextindex;
    values.delay = round(rand(1, 4)) * 1000;
    };
    while (values.throw_to == values.ball_at){
        values.deprecated +=1;
        values.throw_to = list.throwschedule.nextvalue;
        values.delay = list.delayschedule.nextvalue;
    };
]

/ ontrialend = [
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.throwcount += 1;
    if (values.ball_at == 2) {
        values.player2thrown += 1;
    };
]

/ stimulusframes = [1=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    stats]

/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = values.delay
/ branch = [
    return trial.throw;
]
</trial>

// handles the human player
<trial player2>
/ ontrialbegin = [
    values.received_from = values.ball_at;
    expressions.set_offsets;
    
    values.player2received += 1;
    
    values.player1state = 1;
    //catch
    values.player2state = 2;
    values.player3state = 1;
    values.player4state = 1;
    values.player5state = 1;
    values.player6state = 1;
    values.player7state = 1;
    values.player8state = 1;
    values.player9state = 1;
    
    values.ball_at = 2;
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    
]

/ ontrialend = [
    values.throw_to = substring(trial.player2.response, length(trial.player2.response)-1, 1);
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.player2thrown += 1;
    values.throwcount += 1;
]

/ stimulusframes = [1=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    stats]

/ validresponse = ("4", "9", player4, player5, player6, player7, player8, player9)
/ responsemessage = ("4", player1click, 100)
/ responsemessage = ("9", player3click, 100)
/ responsemessage = (player4, player4click, 100)
/ responsemessage = (player5, player5click, 100)
/ responsemessage = (player6, player6click, 100)
/ responsemessage = (player7, player7click, 100)
/ responsemessage = (player8, player8click, 100)
/ responsemessage = (player9, player9click, 100)
/ inputdevice = keyboard
/ branch = [
 if (trial.player2.response == 5) 
values.throw_to == 1
 return trial.throw;
]
/ branch = [
  if (trial.player2.response == 10) /
    values.throw_to == 3
    return trial.throw;
]
</trial>

// implements the throw animation
<trial throw>
/ ontrialbegin = [
    picture.player1.skip = expressions.skip_player1pic;
    picture.player2.skip = expressions.skip_player2pic;
    picture.player3.skip = expressions.skip_player3pic;
    picture.player4.skip = expressions.skip_player4pic;
    picture.player5.skip = expressions.skip_player5pic;
    picture.player6.skip = expressions.skip_player6pic;
    picture.player7.skip = expressions.skip_player7pic;
    picture.player8.skip = expressions.skip_player8pic;
    picture.player9.skip = expressions.skip_player9pic;
    
    values.throwingplayer_x = list.player_x.item(values.ball_at);
    values.throwingplayer_y = list.player_y.item(values.ball_at);
    values.receivingplayer_x = list.player_x.item(values.throw_to);
    values.receivingplayer_y = list.player_y.item(values.throw_to);
    values.ball_x = values.receivingplayer_x;
    expressions.set_throwoffset;
]

/ ontrialend = [
    if (values.throwcount >= parameters.nthrows){
        values.stop = true;
    } else {
        values.stop = false;
    };
    picture.player1.skip = false;
    picture.player2.skip = false;
    picture.player3.skip = false;
    picture.player4.skip = false;
    picture.player5.skip = false;
    picture.player6.skip = false;
    picture.player7.skip = false;
    picture.player8.skip = false;
    picture.player9.skip = false;
]

/ stimulustimes = [0=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow0, stats;
    
    500=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow1, stats;
    
    600=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow2, stats;
    
    700=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow3, stats;
    
    800=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow4, stats;
    
    900=ball_to]
    
/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = 900 + expressions.throwduration
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// displays the welcome message / instructions / game cover story
<trial instructions>
/ stimulusframes = [1=clearscreen, banner, logo, instructions, play]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

<trial instructions2>
/ stimulusframes = [1=getReady]
/ trialduration = parameters.readyDuration
/ beginresponsetime = parameters.readyDuration
/ recorddata = false
</trial>

// displays the "Connecting to other players..." message and animation
<trial start>
/ ontrialbegin = [
    list.npcs.reset();
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.ball_x = list.player_x.item(values.throw_to);
]
/ stimulusframes = [1=clearscreen, connectingmessage, connectinganimation]
/ inputdevice = keyboard
/ validresponse = (0)
/ trialduration = replace(5000,6000,7000)
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// end screen with exit button
<trial thankyou>
/ stimulusframes = [1=clearscreen, thankyoumessage, exit]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>


We are running out of time and are in quite a predicament. Any help you can provide would be greatly appreciated. Thank you in advance.

/ branch = [
if (trial.player2.response == 5)
values.throw_to == 1 // issue 1: wrong operator; issue 2: missing statement separator
return trial.throw;
]
/ branch = [
if (trial.player2.response == 10) /
values.throw_to == 3 // issue 1: wrong operator; issue 2: missing statement separator
return trial.throw;
]


Your /branch logic in <trial player2> is wrong and broken.

FIrst, == is the wrong operator; it's a comparison operator, not the assignment operator. If you want to set values.throw_to based on the player's response, you need =.
https://www.millisecond.com/support/docs/current/html/language/expressions/operators.htm

Second, you're missing the statement separator after setting values.throw_to.
https://www.millisecond.com/support/docs/current/html/language/expressions/operators.htm

Expressed correctly, those branches ought to read

/ branch = [
if (trial.player2.response == 5)
values.throw_to = 1; // use assignment operator, separate statements properly
return trial.throw;
]
/ branch = [
if (trial.player2.response == 10) /
values.throw_to = 3; // use assignment operator, separate statements properly
return trial.throw;
]



periperiperika555
periperiperika555
Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)
Group: Forum Members
Posts: 5, Visits: 11

Dear Dave,

Thank you so much for your guidance. Following your advice, I was able to rewrite it, and now it's working perfectly! It looks like my experiment is on track to succeed. I genuinely appreciate your help.
periperiperika555
periperiperika555
Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)
Group: Forum Members
Posts: 5, Visits: 11

Hello, Dave.

May I ask another question?
We are looking to program a Cyberball game with 30 throws in 4 sets, automatically repeating. However, currently, after one set, it goes to "trial.end," and we can't seem to run the 4 sets consecutively.
We would like to have it in a pattern like

"Cyberball game -> 10-second break -> Cyberball game -> 10-second break...".

If we can achieve this, our experiment will be complete. Could you please assist us with this?




<trial throw>
/ ontrialbegin = [
    picture.player1.skip = expressions.skip_player1pic;
    picture.player2.skip = expressions.skip_player2pic;
    picture.player3.skip = expressions.skip_player3pic;
    
    values.throwingplayer_x = list.player_x.item(values.ball_at);
    values.throwingplayer_y = list.player_y.item(values.ball_at);
    values.receivingplayer_x = list.player_x.item(values.throw_to);
    values.receivingplayer_y = list.player_y.item(values.throw_to);
    values.ball_x = values.receivingplayer_x;
    expressions.set_throwoffset;
]

/ ontrialend = [
    if (values.throwcount >= parameters.nthrows){
        values.stop = true;
    } else {
        values.stop = false;
    };
    picture.player1.skip = false;
    picture.player2.skip = false;
    picture.player3.skip = false;
]

/ stimulustimes = [0=clearscreen, pla……
    playerthrow4, stats;
    
    ……900=ball_to]
    
/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = 900 + expressions.throwduration
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// displays the welcome message / instructions / game cover story
<trial instructions>
/ stimulusframes = [1=clearscreen, banner, logo, instructions, play]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

<trial instructions2>
/ stimulusframes = [1=getReady]
/ trialduration = parameters.readyDuration
/ beginresponsetime = parameters.readyDuration
/ recorddata = false
</trial>

// displays the "Connecting to other players..." message and animation
<trial start>
/ ontrialbegin = [
    list.npcs.reset();
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.ball_x = list.player_x.item(values.throw_to);
]
/ stimulusframes = [1=clearscreen, connectingmessage, connectinganimation]
/ inputdevice = keyboard
/ validresponse = (0)
/ trialduration = replace(5000,6000,7000)
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// end screen with exit button
<trial thankyou>
/ stimulusframes = [1=clearscreen, thankyoumessage, exit]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

<block cyberball>
/ stop = [
    values.stop;
]
/ trials = [1=instructions; 2=start]
</block>

<block cyberball2>
/ stop = [
    values.stop;
]
/ trials = [1=instructions2; 2=start]
</block>

<block end>
/ trials = [1=thankyou]
</block>


<expt default>
/ onexptbegin = [
    expressions.set_sizes_and_positions;
]
/ blocks = [1=generateschedule; 2=cyberball; 3=generateschedule; 4=cyberball2; 5=end]
/ groups = (1 of 5)
</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: 104K
periperiperika555 - 10/6/2023

Hello, Dave.

May I ask another question?
We are looking to program a Cyberball game with 30 throws in 4 sets, automatically repeating. However, currently, after one set, it goes to "trial.end," and we can't seem to run the 4 sets consecutively.
We would like to have it in a pattern like

"Cyberball game -> 10-second break -> Cyberball game -> 10-second break...".

If we can achieve this, our experiment will be complete. Could you please assist us with this?




<trial throw>
/ ontrialbegin = [
    picture.player1.skip = expressions.skip_player1pic;
    picture.player2.skip = expressions.skip_player2pic;
    picture.player3.skip = expressions.skip_player3pic;
    
    values.throwingplayer_x = list.player_x.item(values.ball_at);
    values.throwingplayer_y = list.player_y.item(values.ball_at);
    values.receivingplayer_x = list.player_x.item(values.throw_to);
    values.receivingplayer_y = list.player_y.item(values.throw_to);
    values.ball_x = values.receivingplayer_x;
    expressions.set_throwoffset;
]

/ ontrialend = [
    if (values.throwcount >= parameters.nthrows){
        values.stop = true;
    } else {
        values.stop = false;
    };
    picture.player1.skip = false;
    picture.player2.skip = false;
    picture.player3.skip = false;
]

/ stimulustimes = [0=clearscreen, pla……
    playerthrow4, stats;
    
    ……900=ball_to]
    
/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = 900 + expressions.throwduration
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// displays the welcome message / instructions / game cover story
<trial instructions>
/ stimulusframes = [1=clearscreen, banner, logo, instructions, play]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

<trial instructions2>
/ stimulusframes = [1=getReady]
/ trialduration = parameters.readyDuration
/ beginresponsetime = parameters.readyDuration
/ recorddata = false
</trial>

// displays the "Connecting to other players..." message and animation
<trial start>
/ ontrialbegin = [
    list.npcs.reset();
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.ball_x = list.player_x.item(values.throw_to);
]
/ stimulusframes = [1=clearscreen, connectingmessage, connectinganimation]
/ inputdevice = keyboard
/ validresponse = (0)
/ trialduration = replace(5000,6000,7000)
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// end screen with exit button
<trial thankyou>
/ stimulusframes = [1=clearscreen, thankyoumessage, exit]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

<block cyberball>
/ stop = [
    values.stop;
]
/ trials = [1=instructions; 2=start]
</block>

<block cyberball2>
/ stop = [
    values.stop;
]
/ trials = [1=instructions2; 2=start]
</block>

<block end>
/ trials = [1=thankyou]
</block>


<expt default>
/ onexptbegin = [
    expressions.set_sizes_and_positions;
]
/ blocks = [1=generateschedule; 2=cyberball; 3=generateschedule; 4=cyberball2; 5=end]
/ groups = (1 of 5)
</expt>

You need to set values.stop back to false and values.throwcount back to 0 between sets, e,g, /onblockbegin in <block generateschedule>,
periperiperika555
periperiperika555
Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)
Group: Forum Members
Posts: 5, Visits: 11
Hello Dave,

I hope you're well. I wanted to thank you for your advice yesterday. I tried implementing your suggestions, but now the game seems to go on forever and doesn't stop after one set. I've included the changes I made below. Could you please let me know if I've made the corrections correctly? I apologize for the multiple inquiries, and thank you for your assistance.


<trial npctrial>
/ ontrialbegin = [
    values.received_from = values.ball_at;
    values.ball_at = values.throw_to;
    if (values.ball_at == 2) {
        values.player2received += 1;
    };
    expressions.set_offsets;
    
    values.player1state = (values.ball_at == 1) + 1;
    values.player2state = (values.ball_at == 2) + 1;
    values.player3state = (values.ball_at == 3) + 1;
    values.player4state = (values.ball_at == 4) + 1;
    values.player5state = (values.ball_at == 5) + 1;
    values.player6state = (values.ball_at == 6) + 1;
    values.player7state = (values.ball_at == 7) + 1;
    values.player8state = (values.ball_at == 8) + 1;
    values.player9state = (values.ball_at == 9) + 1;
    
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    if (values.throw_to == 0){
    values.throw_to = list.npcs.nextindex;
    values.delay = round(rand(1, 4)) * 1000;
    };
    while (values.throw_to == values.ball_at){
        values.deprecated +=1;
        values.throw_to = list.throwschedule.nextvalue;
        values.delay = list.delayschedule.nextvalue;
    };
]

/ ontrialend = [
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.throwcount += 0;
    if (values.ball_at == 2) {
        values.player2thrown += 1;
    };
]

/ stimulusframes = [1=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    stats]

/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = values.delay
/ branch = [
    return trial.throw;
]
</trial>

// handles the human player
<trial player2>
/ ontrialbegin = [
    values.received_from = values.ball_at;
    expressions.set_offsets;
    
    values.player2received += 1;
    
    values.player1state = 1;
    //catch
    values.player2state = 2;
    values.player3state = 1;
    values.player4state = 1;
    values.player5state = 1;
    values.player6state = 1;
    values.player7state = 1;
    values.player8state = 1;
    values.player9state = 1;
    
    values.ball_at = 2;
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    
]

/ ontrialend = [
    values.throw_to = substring(trial.player2.response, length(trial.player2.response)-1, 1);
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.player2thrown += 1;
    values.throwcount += 0;
]

/ stimulusframes = [1=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    stats]

/ validresponse = ("4", "2", player4, player5, player6, player7, player8, player9)
/ responsemessage = ("4", player1click, 100)
/ responsemessage = ("2", player3click, 100)
/ responsemessage = (player4, player4click, 100)
/ responsemessage = (player5, player5click, 100)
/ responsemessage = (player6, player6click, 100)
/ responsemessage = (player7, player7click, 100)
/ responsemessage = (player8, player8click, 100)
/ responsemessage = (player9, player9click, 100)
/ inputdevice = keyboard
/ branch = [
 if (trial.player2.response == 5)
values.throw_to = 1;
 return trial.throw;
]
/ branch = [
  if (trial.player2.response == 3)
    values.throw_to = 3;
    return trial.throw;
]
</trial>

// implements the throw animation
<trial throw>
/ ontrialbegin = [
    picture.player1.skip = expressions.skip_player1pic;
    picture.player2.skip = expressions.skip_player2pic;
    picture.player3.skip = expressions.skip_player3pic;
    picture.player4.skip = expressions.skip_player4pic;
    picture.player5.skip = expressions.skip_player5pic;
    picture.player6.skip = expressions.skip_player6pic;
    picture.player7.skip = expressions.skip_player7pic;
    picture.player8.skip = expressions.skip_player8pic;
    picture.player9.skip = expressions.skip_player9pic;
    
    values.throwingplayer_x = list.player_x.item(values.ball_at);
    values.throwingplayer_y = list.player_y.item(values.ball_at);
    values.receivingplayer_x = list.player_x.item(values.throw_to);
    values.receivingplayer_y = list.player_y.item(values.throw_to);
    values.ball_x = values.receivingplayer_x;
    expressions.set_throwoffset;
]

/ ontrialend = [
    if (values.throwcount >= parameters.nthrows){
        values.stop = false;
    } else {
        values.stop = false;
    };
    picture.player1.skip = false;
    picture.player2.skip = false;
    picture.player3.skip = false;
    picture.player4.skip = false;
    picture.player5.skip = false;
    picture.player6.skip = false;
    picture.player7.skip = false;
    picture.player8.skip = false;
    picture.player9.skip = false;
]

/ stimulustimes = [0=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow0, stats;
    
    500=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow1, stats;
    
    600=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow2, stats;
    
    700=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow3, stats;
    
    800=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow4, stats;
    
    900=ball_to]
    
/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = 900 + expressions.throwduration
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// displays the welcome message / instructions / game cover story
<trial instructions>
/ stimulusframes = [1=clearscreen, banner, logo, instructions, play]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

<trial instructions2>
/ stimulusframes = [1=getReady]
/ trialduration = parameters.readyDuration
/ beginresponsetime = parameters.readyDuration
/ recorddata = false
</trial>

// displays the "Connecting to other players..." message and animation
<trial start>
/ ontrialbegin = [
    list.npcs.reset();
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.ball_x = list.player_x.item(values.throw_to);
]
/ stimulusframes = [1=clearscreen, connectingmessage, connectinganimation]
/ inputdevice = keyboard
/ validresponse = (0)
/ trialduration = replace(5000,6000,7000)
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// end screen with exit button
<trial thankyou>
/ stimulusframes = [1=clearscreen, thankyoumessage, exit]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

**************************************************************************************************************
**************************************************************************************************************
    BLOCKS
**************************************************************************************************************
**************************************************************************************************************

<block cyberball>
/ stop = [
    values.stop;
]
/ trials = [1=start]
</block>

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

</block>

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

</block>


<block cyberball2>
/ stop = [
    values.stop;
]
/ trials = [1=start]
</block>

<block end>
/ trials = [1=thankyou]
</block>

**************************************************************************************************************
**************************************************************************************************************
    EXPERIMENT
**************************************************************************************************************
**************************************************************************************************************
// runs a game with the default parameter settings at the top of the script
<expt default>
/ onexptbegin = [
    expressions.set_sizes_and_positions;
]
/ blocks = [1=generateschedule; 2=instructions; 3=cyberball; 4=instructions2; 5=cyberball; 6=end]
/ groups = (1 of 5)
</expt>





I appreciate your help and apologize again for any inconvenience.

Best regards,
Saito
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
periperiperika555 - 10/7/2023
Hello Dave,

I hope you're well. I wanted to thank you for your advice yesterday. I tried implementing your suggestions, but now the game seems to go on forever and doesn't stop after one set. I've included the changes I made below. Could you please let me know if I've made the corrections correctly? I apologize for the multiple inquiries, and thank you for your assistance.


<trial npctrial>
/ ontrialbegin = [
    values.received_from = values.ball_at;
    values.ball_at = values.throw_to;
    if (values.ball_at == 2) {
        values.player2received += 1;
    };
    expressions.set_offsets;
    
    values.player1state = (values.ball_at == 1) + 1;
    values.player2state = (values.ball_at == 2) + 1;
    values.player3state = (values.ball_at == 3) + 1;
    values.player4state = (values.ball_at == 4) + 1;
    values.player5state = (values.ball_at == 5) + 1;
    values.player6state = (values.ball_at == 6) + 1;
    values.player7state = (values.ball_at == 7) + 1;
    values.player8state = (values.ball_at == 8) + 1;
    values.player9state = (values.ball_at == 9) + 1;
    
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    if (values.throw_to == 0){
    values.throw_to = list.npcs.nextindex;
    values.delay = round(rand(1, 4)) * 1000;
    };
    while (values.throw_to == values.ball_at){
        values.deprecated +=1;
        values.throw_to = list.throwschedule.nextvalue;
        values.delay = list.delayschedule.nextvalue;
    };
]

/ ontrialend = [
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.throwcount += 0;
    if (values.ball_at == 2) {
        values.player2thrown += 1;
    };
]

/ stimulusframes = [1=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    stats]

/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = values.delay
/ branch = [
    return trial.throw;
]
</trial>

// handles the human player
<trial player2>
/ ontrialbegin = [
    values.received_from = values.ball_at;
    expressions.set_offsets;
    
    values.player2received += 1;
    
    values.player1state = 1;
    //catch
    values.player2state = 2;
    values.player3state = 1;
    values.player4state = 1;
    values.player5state = 1;
    values.player6state = 1;
    values.player7state = 1;
    values.player8state = 1;
    values.player9state = 1;
    
    values.ball_at = 2;
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    
]

/ ontrialend = [
    values.throw_to = substring(trial.player2.response, length(trial.player2.response)-1, 1);
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.player2thrown += 1;
    values.throwcount += 0;
]

/ stimulusframes = [1=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    stats]

/ validresponse = ("4", "2", player4, player5, player6, player7, player8, player9)
/ responsemessage = ("4", player1click, 100)
/ responsemessage = ("2", player3click, 100)
/ responsemessage = (player4, player4click, 100)
/ responsemessage = (player5, player5click, 100)
/ responsemessage = (player6, player6click, 100)
/ responsemessage = (player7, player7click, 100)
/ responsemessage = (player8, player8click, 100)
/ responsemessage = (player9, player9click, 100)
/ inputdevice = keyboard
/ branch = [
 if (trial.player2.response == 5)
values.throw_to = 1;
 return trial.throw;
]
/ branch = [
  if (trial.player2.response == 3)
    values.throw_to = 3;
    return trial.throw;
]
</trial>

// implements the throw animation
<trial throw>
/ ontrialbegin = [
    picture.player1.skip = expressions.skip_player1pic;
    picture.player2.skip = expressions.skip_player2pic;
    picture.player3.skip = expressions.skip_player3pic;
    picture.player4.skip = expressions.skip_player4pic;
    picture.player5.skip = expressions.skip_player5pic;
    picture.player6.skip = expressions.skip_player6pic;
    picture.player7.skip = expressions.skip_player7pic;
    picture.player8.skip = expressions.skip_player8pic;
    picture.player9.skip = expressions.skip_player9pic;
    
    values.throwingplayer_x = list.player_x.item(values.ball_at);
    values.throwingplayer_y = list.player_y.item(values.ball_at);
    values.receivingplayer_x = list.player_x.item(values.throw_to);
    values.receivingplayer_y = list.player_y.item(values.throw_to);
    values.ball_x = values.receivingplayer_x;
    expressions.set_throwoffset;
]

/ ontrialend = [
    if (values.throwcount >= parameters.nthrows){
        values.stop = false;
    } else {
        values.stop = false;
    };
    picture.player1.skip = false;
    picture.player2.skip = false;
    picture.player3.skip = false;
    picture.player4.skip = false;
    picture.player5.skip = false;
    picture.player6.skip = false;
    picture.player7.skip = false;
    picture.player8.skip = false;
    picture.player9.skip = false;
]

/ stimulustimes = [0=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow0, stats;
    
    500=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow1, stats;
    
    600=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow2, stats;
    
    700=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow3, stats;
    
    800=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow4, stats;
    
    900=ball_to]
    
/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = 900 + expressions.throwduration
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// displays the welcome message / instructions / game cover story
<trial instructions>
/ stimulusframes = [1=clearscreen, banner, logo, instructions, play]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

<trial instructions2>
/ stimulusframes = [1=getReady]
/ trialduration = parameters.readyDuration
/ beginresponsetime = parameters.readyDuration
/ recorddata = false
</trial>

// displays the "Connecting to other players..." message and animation
<trial start>
/ ontrialbegin = [
    list.npcs.reset();
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.ball_x = list.player_x.item(values.throw_to);
]
/ stimulusframes = [1=clearscreen, connectingmessage, connectinganimation]
/ inputdevice = keyboard
/ validresponse = (0)
/ trialduration = replace(5000,6000,7000)
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// end screen with exit button
<trial thankyou>
/ stimulusframes = [1=clearscreen, thankyoumessage, exit]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

**************************************************************************************************************
**************************************************************************************************************
    BLOCKS
**************************************************************************************************************
**************************************************************************************************************

<block cyberball>
/ stop = [
    values.stop;
]
/ trials = [1=start]
</block>

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

</block>

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

</block>


<block cyberball2>
/ stop = [
    values.stop;
]
/ trials = [1=start]
</block>

<block end>
/ trials = [1=thankyou]
</block>

**************************************************************************************************************
**************************************************************************************************************
    EXPERIMENT
**************************************************************************************************************
**************************************************************************************************************
// runs a game with the default parameter settings at the top of the script
<expt default>
/ onexptbegin = [
    expressions.set_sizes_and_positions;
]
/ blocks = [1=generateschedule; 2=instructions; 3=cyberball; 4=instructions2; 5=cyberball; 6=end]
/ groups = (1 of 5)
</expt>





I appreciate your help and apologize again for any inconvenience.

Best regards,
Saito

Nowhere in that code do you include where you set values.stop back to false and values.throwcount back to 0, which are the relevant changes.

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
Dave - 10/9/2023
periperiperika555 - 10/7/2023
Hello Dave,

I hope you're well. I wanted to thank you for your advice yesterday. I tried implementing your suggestions, but now the game seems to go on forever and doesn't stop after one set. I've included the changes I made below. Could you please let me know if I've made the corrections correctly? I apologize for the multiple inquiries, and thank you for your assistance.


<trial npctrial>
/ ontrialbegin = [
    values.received_from = values.ball_at;
    values.ball_at = values.throw_to;
    if (values.ball_at == 2) {
        values.player2received += 1;
    };
    expressions.set_offsets;
    
    values.player1state = (values.ball_at == 1) + 1;
    values.player2state = (values.ball_at == 2) + 1;
    values.player3state = (values.ball_at == 3) + 1;
    values.player4state = (values.ball_at == 4) + 1;
    values.player5state = (values.ball_at == 5) + 1;
    values.player6state = (values.ball_at == 6) + 1;
    values.player7state = (values.ball_at == 7) + 1;
    values.player8state = (values.ball_at == 8) + 1;
    values.player9state = (values.ball_at == 9) + 1;
    
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    if (values.throw_to == 0){
    values.throw_to = list.npcs.nextindex;
    values.delay = round(rand(1, 4)) * 1000;
    };
    while (values.throw_to == values.ball_at){
        values.deprecated +=1;
        values.throw_to = list.throwschedule.nextvalue;
        values.delay = list.delayschedule.nextvalue;
    };
]

/ ontrialend = [
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.throwcount += 0;
    if (values.ball_at == 2) {
        values.player2thrown += 1;
    };
]

/ stimulusframes = [1=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    stats]

/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = values.delay
/ branch = [
    return trial.throw;
]
</trial>

// handles the human player
<trial player2>
/ ontrialbegin = [
    values.received_from = values.ball_at;
    expressions.set_offsets;
    
    values.player2received += 1;
    
    values.player1state = 1;
    //catch
    values.player2state = 2;
    values.player3state = 1;
    values.player4state = 1;
    values.player5state = 1;
    values.player6state = 1;
    values.player7state = 1;
    values.player8state = 1;
    values.player9state = 1;
    
    values.ball_at = 2;
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    
]

/ ontrialend = [
    values.throw_to = substring(trial.player2.response, length(trial.player2.response)-1, 1);
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.player2thrown += 1;
    values.throwcount += 0;
]

/ stimulusframes = [1=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    stats]

/ validresponse = ("4", "2", player4, player5, player6, player7, player8, player9)
/ responsemessage = ("4", player1click, 100)
/ responsemessage = ("2", player3click, 100)
/ responsemessage = (player4, player4click, 100)
/ responsemessage = (player5, player5click, 100)
/ responsemessage = (player6, player6click, 100)
/ responsemessage = (player7, player7click, 100)
/ responsemessage = (player8, player8click, 100)
/ responsemessage = (player9, player9click, 100)
/ inputdevice = keyboard
/ branch = [
 if (trial.player2.response == 5)
values.throw_to = 1;
 return trial.throw;
]
/ branch = [
  if (trial.player2.response == 3)
    values.throw_to = 3;
    return trial.throw;
]
</trial>

// implements the throw animation
<trial throw>
/ ontrialbegin = [
    picture.player1.skip = expressions.skip_player1pic;
    picture.player2.skip = expressions.skip_player2pic;
    picture.player3.skip = expressions.skip_player3pic;
    picture.player4.skip = expressions.skip_player4pic;
    picture.player5.skip = expressions.skip_player5pic;
    picture.player6.skip = expressions.skip_player6pic;
    picture.player7.skip = expressions.skip_player7pic;
    picture.player8.skip = expressions.skip_player8pic;
    picture.player9.skip = expressions.skip_player9pic;
    
    values.throwingplayer_x = list.player_x.item(values.ball_at);
    values.throwingplayer_y = list.player_y.item(values.ball_at);
    values.receivingplayer_x = list.player_x.item(values.throw_to);
    values.receivingplayer_y = list.player_y.item(values.throw_to);
    values.ball_x = values.receivingplayer_x;
    expressions.set_throwoffset;
]

/ ontrialend = [
    if (values.throwcount >= parameters.nthrows){
        values.stop = false;
    } else {
        values.stop = false;
    };
    picture.player1.skip = false;
    picture.player2.skip = false;
    picture.player3.skip = false;
    picture.player4.skip = false;
    picture.player5.skip = false;
    picture.player6.skip = false;
    picture.player7.skip = false;
    picture.player8.skip = false;
    picture.player9.skip = false;
]

/ stimulustimes = [0=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow0, stats;
    
    500=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow1, stats;
    
    600=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow2, stats;
    
    700=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow3, stats;
    
    800=clearscreen, player1, player2, player3, player4, player5, player6, player7, player8, player9,
    player1label, player2label, player3label, player4label, player5label, player6label, player7label, player8label, player9label,
    player1avatar, player2avatar, player3avatar, player4avatar, player5avatar, player6avatar, player7avatar, player8avatar, player9avatar,
    playerthrow4, stats;
    
    900=ball_to]
    
/ inputdevice = keyboard
/ showmousecursor = false
/ validresponse = (0)
/ trialduration = 900 + expressions.throwduration
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// displays the welcome message / instructions / game cover story
<trial instructions>
/ stimulusframes = [1=clearscreen, banner, logo, instructions, play]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

<trial instructions2>
/ stimulusframes = [1=getReady]
/ trialduration = parameters.readyDuration
/ beginresponsetime = parameters.readyDuration
/ recorddata = false
</trial>

// displays the "Connecting to other players..." message and animation
<trial start>
/ ontrialbegin = [
    list.npcs.reset();
    values.throw_to = list.throwschedule.nextvalue;
    values.delay = list.delayschedule.nextvalue;
    values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
    values.ball_x = list.player_x.item(values.throw_to);
]
/ stimulusframes = [1=clearscreen, connectingmessage, connectinganimation]
/ inputdevice = keyboard
/ validresponse = (0)
/ trialduration = replace(5000,6000,7000)
/ branch = [
    if (values.throw_to == 2 && !parameters.spectate){
        return trial.player2;
    } else {
        return trial.npctrial;
    }
]
/ recorddata = false
</trial>

// end screen with exit button
<trial thankyou>
/ stimulusframes = [1=clearscreen, thankyoumessage, exit]
/ validresponse = (lbuttondblclk)
/ recorddata = false
/ inputdevice = mousekey
</trial>

**************************************************************************************************************
**************************************************************************************************************
    BLOCKS
**************************************************************************************************************
**************************************************************************************************************

<block cyberball>
/ stop = [
    values.stop;
]
/ trials = [1=start]
</block>

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

</block>

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

</block>


<block cyberball2>
/ stop = [
    values.stop;
]
/ trials = [1=start]
</block>

<block end>
/ trials = [1=thankyou]
</block>

**************************************************************************************************************
**************************************************************************************************************
    EXPERIMENT
**************************************************************************************************************
**************************************************************************************************************
// runs a game with the default parameter settings at the top of the script
<expt default>
/ onexptbegin = [
    expressions.set_sizes_and_positions;
]
/ blocks = [1=generateschedule; 2=instructions; 3=cyberball; 4=instructions2; 5=cyberball; 6=end]
/ groups = (1 of 5)
</expt>





I appreciate your help and apologize again for any inconvenience.

Best regards,
Saito

Nowhere in that code do you include where you set values.stop back to false and values.throwcount back to 0, which are the relevant changes.

The big mistake in the code you posted is that you do not ever increase the throwcount anymore, so the block has no way of knowing when to stop. You really need to fix that.

/ ontrialend = [
values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
values.throwcount += 0; // this is wrong; throwcount needs to be increased by 1 on every throw
if (values.ball_at == 2) {
values.player2thrown += 1;
};
]


/ ontrialend = [
values.throw_to = substring(trial.player2.response, length(trial.player2.response)-1, 1);
values.realizedThrowSchedule = concat(values.realizedThrowSchedule, values.throw_to);
values.player2thrown += 1;
values.throwcount += 0; // this is wrong; throwcount needs to be increased by 1 on every throw
]

Edited Last Year by Dave
periperiperika555
periperiperika555
Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)Associate Member (64 reputation)
Group: Forum Members
Posts: 5, Visits: 11
Dear Dave,

Thank you for your prompt response! It seems I had misunderstood, and after understanding and making the necessary corrections, the program now works perfectly as intended. I sincerely appreciate you guiding me with the correct code. Thanks to you, we have successfully completed the program we wanted to create. I cannot express my gratitude enough. Thank you very much.

Best regards,
Saito
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search