Shelf occasionally returns default / shelf await duration

Hi all, I am using the shelf counter functions for a simple participant counter. I’ve modeled the code on the examples provided here. Most of the time this seems to work-- the counter always increments and I’m able to pull the counter value via the await command. This takes about 13 seconds, so I’ve moved the code from the start experiment (since this is a little long to wait on a blank screen) to the instructions.

On occasion however, I immediately get a default value (e.g. 0) returned by the await code (same script, just rerunning after clearing cache etc) rather than the actual shelf value. Curious whether other people have similar experiences with the retrieval time or getting default values with await psychoJS.shelf.getIntegerValue or other shelf calls.

Including relevant js code part below. I’ve put it in the ‘begin routine’ tab of a code component in the second instruction slide routine. The default is not returned very frequently, so I’m not sure if this also happens when the code is under ‘begin experiment.’ Wondering whether this is related to experiment configuration or communication with the pavlovia servers. I’ll try to figure out more info about when/how often the default value is returned.

// increment participant start number
console.log("BEFORE ADDINTEGER CALL")
psychoJS.shelf.addIntegerValue({key: ['participant_counter'], delta: 1});

// get current incremented participant_counter numbre for use in assigning stimlist
console.log("BEFORE AWAIT CALL")
participantN = await psychoJS.shelf.getIntegerValue({key: ['participant_counter'], defaultValue: 0});
console.log("AFTER AWAIT CALL. VALUE OF participantN is: " + participantN)

What sort of Internet connection do you have?

You seem to have two calls and one without await. How about. It should only take about 1 second per call. How about trying to get the current value (with await), then add 1, then store the new value asynchronously.

What sort of Internet connection do you have?

You seem to have two calls and one without await. How about. It should only take about 1 second per call. How about trying to get the current value (with await), then add 1, then store the new value asynchronously.

Yes I think the long await duration might have been due to the near-simultaneous interaction with the shelf counter. I’ve just tried something similar which is to put just the addIntegerValue line in the ‘Begin Experiment’ tab and now the await call in the same place during the instructions returns the value in just a second. It seems like getting the default value returned was probably caused by the same issue that was delaying the await call. Working well now-- thanks!