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: 79 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 En ligne Administrateur Points: 25437 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: 79 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: 79 Défis: 0 Message

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


and ther saving works now thanks
Lephenixnoir En ligne Administrateur Points: 25437 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: 79 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
Calamari Hors ligne Membre Points: 563 Défis: 0 Message

Citer : Posté le 12/10/2025 10:59 | #


You can avoid it by not using the gray engine. But, it seems like if you invoke it even once then this will happen. What I've done in my apps is is disable the gray engine, draw a screen telling the user to press a key to continue (and maybe include a fun graphic or such), then call gint_osmenu(). When the user returns to your program they'll see the screen you drew and know what to do.
“Remember to have fun doing this, or it ain't worth it.” — Robert Alan Koeneke
“They call me the king of the spreadsheets, got 'em all printed out on my bedsheets.” — “Weird Al” Yankovic
Lephenixnoir En ligne Administrateur Points: 25437 Défis: 174 Message

Citer : Posté le 12/10/2025 11:06 | #


Simnon a écrit :
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

For the record, this is a current gint limitation (on fx-series). Both gint_setrestart() and gint_osmenu() use a mechanism dubbed "return-to-menu" which shows the main menu to the user without completely stopping the add-in.

The only official way to do that in the OS is by calling GetKey() a certain way, and GetKey() doesn't return immediately when you re-enter the add-in; it returns when you re-enter the add-in then press a new key. Which is why you have this behavior.

On fx-CG we found a way to call an internal OS function that's not GetKey() and allows return-to-menu without this effect. However, this hasn't been done on fx-series yet.
Mon graphe (27 Juin): (MQ || Rogue Life) ; serial gint ; passe gint 3 ; Azur ; ...) || (shoutbox v5 ; v5)

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 88 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