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