Is anyone using anki-persistence with key-value pairs?

For the uninitiated, anki-persistence is a tool to persist javascript variables between one side of a card to the other. As far as I know, it’s the only consistent method to achieve this, that works both on Desktop and Android. I’m using it to randomize French and Spanish third person pronouns (so not the entire world is all male all the time) and it’s working well.

Now, I’d like to persist a second (independent) variable. For this, the documentation mentions that you can use key-value pairs - but it doesn’t work as described (or at all - it even breaks base functionality). Basically:

Persistence.setItem(value); // this works
Persistence.setItem(key, value); // this doesn’t

Has anyone used anki-persistence to persist more than one variable? If so, do you mind sharing your template?

Thanks in advance

The key has to be a string, this should work for example:


var rand1 = Math.random();
var rand2 = Math.random();

Persistence.setItem("rand1", rand1);
Persistence.setItem("rand2", rand2);

/* Do something with these numbers ... */


var rand1 = Persistence.getItem("rand1");
var rand2 = Persistence.getItem("rand2");

/* Do same thing with these numbers ... */

It absolutely does, of course. Blunder on my part.

Thank you so much, have a good one!