Skip to content
Filippo edited this page Sep 28, 2019 · 1 revision

Summary

FemtoIde have now initial support for PokittoCookies, a special retentive memory area, where you can store some data and retrieve it back after reboot.

Example of use

import femto.mode.Direct;
import femto.Game;
import femto.State;
import femto.input.Button;
import femto.palette.Psygnosia;
import femto.font.TIC80;

class Score extends femto.Cookie {
    Score(){
        super();
        begin("test"); // name of the cookie, up to 8 chars
    }
    int score; // properties you want to save
}

class Main extends State {
    static final var save = new Score(); // previous value is automatically restored
    static final var screen = new Direct(TIC80.font()); // the screenmode we want to draw with

    public static void main(String[] args){
        Game.run( TIC80.font(), new Main() );
    }
    
    void init(){
        screen.clear(0);
    }

    void update(){
        if( Button.A.justPressed() ){
            save.score = Math.random(0, 1000); // update the score
            save.saveCookie(); // save it to eeprom
        }

        screen.setTextPosition( 0, 0 );
        screen.textColor++;
        screen.println("Score: "+save.score); // print the current score
    }
    
}