Randomly selecting participants

28 views
Skip to first unread message

Christian T

unread,
Dec 11, 2023, 8:08:56 AM12/11/23
to classEx - Help and Discussion Forum
Hello everyone,

we are working on something like this: 
  • Group of approx. 14 participants
  • Every participant submits a text (Stage 1)
  • Every participant evaluates the submission of randomly selected 5 other participants in the group (Stage 2)

We want to achieve this with the following code in Stage 2 (with comment):

$rolesarray = $getRoles();  // get all the roles in the group
$key = array_search($role, $array);   //  find the player in this group
unset($rolesarray[$key]);   //  delete player from array of all roles
shuffle($rolesarray);
$rolesarray_rand5=array_slice($rolesarray, 0, 5);   // get five randomly selected (because shuffled) roles

// randomly selected submissions
$other1=$findVariablePartner('slogan1',$round,$partnerRole=$rolesarray_rand5[0],$no_decision=0);
$other2=$findVariablePartner('slogan1',$round,$partnerRole=$rolesarray_rand5[1],$no_decision=0);
$other3=$findVariablePartner('slogan1',$round,$partnerRole=$rolesarray_rand5[2],$no_decision=0);
$other4=$findVariablePartner('slogan1',$round,$partnerRole=$rolesarray_rand5[3],$no_decision=0);
$other5=$findVariablePartner('slogan1',$round,$partnerRole=$rolesarray_rand5[4],$no_decision=0);


However, I get the error message:
Fatal error: Uncaught Error: Call to undefined method D::getRoles() in /var/www/htdocs/bin/classes/D.class.php(204) : eval()'d code:3 Stack trace: #0 /var/www/htdocs/bin/classes/D.class.php(204): eval() #1 /var/www/htdocs/bin/classes/participant/PElementProg.class.php(30): D->setVar() #2 /var/www/htdocs/bin/classes/participant/PSub.class.php(236): PElementProg->showElement() #3 /var/www/htdocs/bin/classes/participant/PPage.class.php(186): PSub->showSub() #4 /var/www/htdocs/bin/index.php(62): PPage->renderStageContainer() #5 {main} thrown in /var/www/htdocs/bin/classes/D.class.php(204) : eval()'d code on line 3

Which I do not get. The problem seems to be $getRoles() which I got from the documentation.

I am grateful for any advice.

Thanks and best,
Christian

Christian T

unread,
Dec 11, 2023, 1:49:14 PM12/11/23
to classEx - Help and Discussion Forum
The problem really seems to be the $getRoles()-function. Using just the first line gives the same error message.

Marcus Giamattei (classEx Team)

unread,
Dec 12, 2023, 3:27:23 AM12/12/23
to classEx - Help and Discussion Forum
Dear Christian, getRoles is a function that can be used only on the lecturer side (https://classex-doc.readthedocs.io/en/latest/Programming.html#functions). Therefore, you have to call the function on the lecturer side into a variable. Then, you can use the variable on the participant side as well. Best, Marcus

Christian T

unread,
Dec 12, 2023, 10:11:45 AM12/12/23
to classEx - Help and Discussion Forum
Hi Marcus,

thank you very much. That solved the problem.

Best,
Christian

Reply all
Reply to author
Forward
0 new messages