Code runs properly for 1 group but fails to save decisions for subsequent groups

15 views
Skip to first unread message

Ankita Acharya

unread,
Mar 1, 2025, 4:20:09 PM3/1/25
to LIONESS Lab help and discussion
Hi,

I hope you are well and thanks in advance for the help. I am running an experiment where a randomly selected proposer enters three values into numeric input boxes. In the next page, I use this code to retrieve the numeric input values. 

-------------------------------
let proposalA = getValue('decisions', 'subjectNr=' + proposer, 'proposalA') || 0;
let proposalB = getValue('decisions', 'subjectNr=' + proposer, 'proposalB') || 0;
let proposalC = getValue('decisions', 'subjectNr=' + proposer, 'proposalC') || 0;

console.log(proposalA, proposalB, proposalC);

// Step 1: Retrieve existing proposalHistory as a string
let proposalHistoryRaw = getValue('proposalHistory') || "";
console.log("Raw proposalHistory retrieved:", proposalHistoryRaw, "Type:", typeof proposalHistoryRaw);

// Step 2: Convert string to an array (handle empty cases)
let proposalHistoryArray = proposalHistoryRaw ? proposalHistoryRaw.split(';') : [];

// Handle cases where `split(';')` might return [""] instead of an empty array
if (proposalHistoryArray.length === 1 && proposalHistoryArray[0] === "") {
    proposalHistoryArray = [];
}

let loopCount = getValue('loopCount');

// Step 3: Format the new proposal entry as a comma-separated string
let newProposalEntry = [loopCount, proposer, proposalA, proposalB, proposalC].join(',');

// Step 4: Add the new entry to the proposal history array
proposalHistoryArray.push(newProposalEntry);
console.log("Added new proposal entry:", newProposalEntry);

// Step 5: Store the updated proposal history back as a semicolon-separated string
record('proposalHistory', proposalHistoryArray.join(';'));
console.log("Updated Proposal History Stored:", proposalHistoryArray.join(';'));

// Convert each entry into an array of values
let parsedProposalHistory = proposalHistoryArray.map(entry => entry.split(','));

console.log("Parsed Proposal History:", parsedProposalHistory);
-------------------------------

This code works properly and outputs accurate values for group 1. However, for groups 2 and onwards, it outputs the attached console log. 

If you have any idea why this is happening, that would be extremely helpful. Thank you for the help!

Best,
Ankita


Screenshot 2025-03-01 at 4.18.43 PM.png

in...@lioness-lab.org

unread,
Mar 3, 2025, 6:11:07 AM3/3/25
to Ankita Acharya, LIONESS Lab help and discussion

Hi Ankita,

 

I believe your code requires also specifying the groupNr to the value of the participants’ current group. So

 

let proposalA = getValue('decisions', 'groupNr='+groupNr+ ' and subjectNr=' + proposer, 'proposalA') || 0;

 

etc

 

cheers, Lucas

--
You received this message because you are subscribed to the Google Groups "LIONESS Lab help and discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lioness-lab...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/lioness-lab/7e656853-ac2a-4b67-a95d-7045d1095dedn%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages