Wilbert's website at SocSci

> ChatGPT

chatgpt/index.html 2025-01-28

ChatGPT

Here is an example how to alter a chatGPT generated code to save to Radcloud Mini. The bold code is what has to be added:

retrieving the participant number from the url

at the start of the script

<script>
var parameters = decodeURIComponent(window.location.search.substring(1)).split("&").reduce((acc,x) => {
	[key, value] = x.split("="); acc[key] = value; return acc
} , {})
try {
	ppn = parameters["ppn"]
} catch (error) {
	ppn = 0
}

saving the data

in the file header

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<script src="datahandler.js"></script>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">

the place where data is saved

Make sure to replace the 8 digit API key (ABCDEF01) with your own Radcloud Mini API key.

function submitResponse() {
	if (currentCoords.x !== null && currentCoords.y !== null) {
		trialData.push({
			trial: currentTrial + 1,
			duration: randomizedDurations[currentTrial],
			x: currentCoords.x,
			y: currentCoords.y
		});
		
		saveData("ABCDEF01", ppn, trialData.slice(-1))
		
		currentTrial++;

		// Show the black screen with + symbol for 1 second
		showBlackScreen();

		// After the black screen, update instruction and move to the next trial
		setTimeout(() => {
			updateInstruction();
		}, 1000);
	}
}

Please note that the code that you receive from ChatGPT should be considered generated and not source so that a journal that you publish in may ask you to supply the source and how the code was generated, therefore always store the AI model that you use and the prompt used for generating it. This does not apply to snippets that you understand yourself and that could have been generated by yourself.