Les membres ayant 30 points peuvent parler sur les canaux annonces, projets et hs du chat.
La shoutbox n'est pas chargée par défaut pour des raisons de performances. Cliquez pour charger.

Forum Casio - Autres questions


Index du Forum » Autres questions » how do i do saving properly
Simnon Hors ligne Membre Points: 62 Défis: 0 Message

how do i do saving properly

Posté le 02/09/2025 19:16

i have this code:


void Save(int field[4][4]){
    int savef = open("/2048s.bin", O_WRONLY | O_CREAT | O_TRUNC);
    write(savef, field, sizeof(int)*4*4);
    close(savef);
}

at main:

while(1){
     if(keypressed(KEY_MENU)){
    Save(field);
        gint_osmenu();
    return 1;
}
        }


when it gets saved sucesfully, it always loads but sometimes it restarts the whole calculator and doesnt save


Lephenixnoir Hors ligne Administrateur Points: 25369 Défis: 174 Message

Citer : Posté le 02/09/2025 19:59 | #


You should world switch to use file functions:

// instead of
Save(field);
// do
gint_world_switch(GINT_CALL(Save, (void *)field));

This gives control of the hardware back to the OS for the duration of the call, which it needs to write files. (The syntax isn't great.)
Mon graphe (27 Juin): (MQ || Rogue Life) ; serial gint ; passe gint 3 ; Azur ; ...) || (shoutbox v5 ; v5)
Simnon Hors ligne Membre Points: 62 Défis: 0 Message

Citer : Posté le 02/09/2025 20:23 | #


also i have to reopen the addin twice after opening it (it returns to menu ater any keypress)adn even then i have to click a button so it updates (i have a dclear and dupdate in the start of main). am i supposed to quit the program wiuth
gint_osmenu();
return 1;
or no
i have gint_setrestart set to 1
Simnon Hors ligne Membre Points: 62 Défis: 0 Message

Citer : Posté le 02/09/2025 20:26 | #


and ther saving works now thanks
Lephenixnoir Hors ligne Administrateur Points: 25369 Défis: 174 Message

Citer : Posté le 02/09/2025 20:32 | #


This exit method is indeed "wrong"; you have two basic options. (1) is to use gint_setrestart() then return from main and after that you can enter the application again, restarting it. (2) is to put gint_osmenu() inside your main loop, then if the user re-enters the add-in execution continues as if nothing had happened. The difference is that (1) leads to your program restarting from the beginning whereas (2) just pauses and resumes it more naturally. If both options are available to you, I recommend (2).

Simnon a écrit :
and ther saving works now thanks

Great!
Mon graphe (27 Juin): (MQ || Rogue Life) ; serial gint ; passe gint 3 ; Azur ; ...) || (shoutbox v5 ; v5)
Simnon Hors ligne Membre Points: 62 Défis: 0 Message

Citer : Posté le 10/09/2025 22:15 | #


so i tried both, but whenever i launch the addin i have to press a key for the screen to update (calling a clear and update in start of main and in the loop)
is that fixable in gint

LienAjouter une imageAjouter une vidéoAjouter un lien vers un profilAjouter du codeCiterAjouter un spoiler(texte affichable/masquable par un clic)Ajouter une barre de progressionItaliqueGrasSoulignéAfficher du texte barréCentréJustifiéPlus petitPlus grandPlus de smileys !
Cliquez pour épingler Cliquez pour détacher Cliquez pour fermer
Alignement de l'image: Redimensionnement de l'image (en pixel):
Afficher la liste des membres
:bow: :cool: :good: :love: ^^
:omg: :fusil: :aie: :argh: :mdr:
:boulet2: :thx: :champ: :whistle: :bounce:
valider
 :)  ;)  :D  :p
 :lol:  8)  :(  :@
 0_0  :oops:  :grr:  :E
 :O  :sry:  :mmm:  :waza:
 :'(  :here:  ^^  >:)

Σ π θ ± α β γ δ Δ σ λ
Veuillez donner la réponse en chiffre
Vous devez activer le Javascript dans votre navigateur pour pouvoir valider ce formulaire.

Si vous n'avez pas volontairement désactivé cette fonctionnalité de votre navigateur, il s'agit probablement d'un bug : contactez l'équipe de Planète Casio.

Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2025 | Il y a 69 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements

Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd