AreaCommonData is the key here indeed. Here are a few snippets from my game.
I save all data for spell cards in a AreaCommonData with the following structure. As you can see I keep separate tracking for Stage game play and Spell Practise.
// Spell practise core. Array for the spell cards to track value
// Structure [ state, captureStage, historyStage, capturePrac, historyPrac, scoreBorder, scoreMagic, scoreReimu, scoreYukari, scoreMarisa, scoreAlice ]
// State 0 = unseen/disabled. 1 = Seen. 2 = Captured.
// Number of captures and tries is as they are.
// 01 spell cards
SetAreaCommonData("core","pierre01hard",[0,0,0,0,0,0,0,0,0,0,0]);
I personally utilize the EVENT system of Danmakufu to detect a spell card start or capturing a spell card. All my spell cards utilize the EVENT section using custom user event:
@Event {
alternative(GetEventType())
case(EV_USER+9999) {
SetCommonData("spellcardID","pierre01hard");
}
}
pierre01hard is a unique value I have given for this spell card. It basically means "Pierre boss" - "Spell card #01" - "Hard mode"
This is inside my "system" script which is launched when the game starts and keeps running in the background. It listens to the default Danmakufu Events.
@Event {
case(EV_START_BOSS_SPELL) {
updateCardHistory();
}
case(EV_GAIN_SPELL) {
updateCardCapture();
}
}
The updateCardHistory and updateCardCapture are functions I wrote myself. It looks roughly like this:
task updateCardHistory() {
let spellScriptID = GetCommonData("spellScriptID", 0);
NotifyEvent(spellScriptID, EV_USER+9999, 0);
getResultCard = GetCommonData("spellcardID", "NULL");
let getCommonSpellCardData = [];
getCommonSpellCardData = GetAreaCommonData("core", getResultCard, [0,0,0,0,0,0,0,0,0,0,0]);
// Do stuff with the values and save it back to the AreaCommonData
}
History value is updated when the spell begins and the capture value is updated when the card is obviously captured. It is a bit code-duplication (ugly), but hey it works.
The flow would be:
- System script is launched and running + listening to events
- System script triggers event on spell card start and gain
- Update function is called which calls the EVENT from the Spell Card script
- Spell Card uniqueID is retrieved and stored
- Values are modified as pleased
- Modified values are saved back
Hope Sparen's and my method gives you some thing to work with.