Persistent Game State

One of the major flaws with the LibreTag system in its current state is that if the power is turned off mid game all the variables containing the players health and remaining ammo are lost. This can either be an annoyance or a way to cheat, either way it needed to be fixed.

I toyed with several ideas like saving all variables to the built in EEPROM every 10 seconds or so, but I was worried that after a while I may wear the EEPROM out. There is also the disadvantage that since the save is happening every 10 seconds people could still cheat in that time window. I finally came across the idea of getting the Picaxe chip to detect when the power is turned off and then save all the variables to EEPROM. By using a large capacitor (2000uf) on the 5v supply line, the Picaxe gets just under a second of runtime before the voltage drops too low.

I initially tried lower capacity capacitors but it was only at about 1500uf that the picaxe managed to stay on long enough to detect the power loss. I created a simple IF statement, once the input voltage dropped below about 5.5v (I’m using a 5v LDO regulator) it went into a loop sending a test character out the serial connection to the pc till the power completely dies. During testing what I saw was really strange since at 1000uf nothing was received, but when using a 1500uf capacitor,  about 20 characters were received. I would have expected that when using a 1000uf to at least get a couple of characters received, I am guessing this is to do with the logarithmic nature of a capacitor.

Anyway like I said with a 2000uf capacitor the Picaxe stays on for long enough to save the health, ammo and number of remaining clips to EEPROM. With a few more modifications to the code, the gun now reads these values back out at power on and hence the game state is preserved. The only thing now is that I have to re-flash the gun once the health or ammo is depleted, which means I better get working on the Admin box to remotely configure the guns…..

Comments are closed.