π
<-

Nspire-Lua Timer not working after closing and then opening

Pour TI-Nspire OS 3.0 ou ultérieur.

Nspire-Lua Timer not working after closing and then opening

Unread postby Rankail » 19 Nov 2020, 17:15

There have been multiple cases where i closed a file on the Ti-Nspire CX and after i open it again it is frozen.
It seems like the timer.start function wont work after reopening a file. This problem cant be replicated in the emulator on PC.
Is this problem already known? And if it is, is there a solution?
Can anyone help me with this?
Last edited by Rankail on 28 Mar 2021, 16:36, edited 1 time in total.
User avatar
Rankail
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Level up: 64%
 
Posts: 21
Joined: 09 Nov 2019, 18:33
Location: Germany, North Rhine-Westfalia
Gender: Male
Calculator(s):
MyCalcs profile
Class: 12

Re: Nspire-Lua Timer not working after closing and then open

Unread postby Rankail » 28 Mar 2021, 16:34

Edit: It is known that the timer stops when the document containing the script is closed. That includes turning off the calculator.
I have the problem that the timer.start function doesn't seem to work when turning the calc of and then on again.
After turning the calc on you see the document for a split second before you return to the home-menu.
If you open the document right now it's in the same state as before you turned the calc of.
Except that the timer was stopped and the timer.start function won't work anymore.

Is there some kind of workaround? Or do i just have to life with this?
User avatar
Rankail
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Level up: 64%
 
Posts: 21
Joined: 09 Nov 2019, 18:33
Location: Germany, North Rhine-Westfalia
Gender: Male
Calculator(s):
MyCalcs profile
Class: 12

Re: Nspire-Lua Timer not working after closing and then open

Unread postby Adriweb » 29 Mar 2021, 03:12

Where do you put the timer.start in your code?
There are some event functions that get launched on start, so it may need to be there. A good place where everything will be initialized (might not be needed in your case, I don't know) would be on.resize

Could you post your code?

MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)
My calculator programs
Mes programmes pour calculatrices
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 79.9%
 
Posts: 14836
Images: 1131
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Twitter: adriweb
GitHub: adriweb

Re: Nspire-Lua Timer not working after closing and then open

Unread postby Rankail » 29 Mar 2021, 09:02

I tried to put it in on.activate. i'll send my code later because i'm on my mobile rn.
User avatar
Rankail
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Level up: 64%
 
Posts: 21
Joined: 09 Nov 2019, 18:33
Location: Germany, North Rhine-Westfalia
Gender: Male
Calculator(s):
MyCalcs profile
Class: 12

Re: Nspire-Lua Timer not working after closing and then open

Unread postby Rankail » 29 Mar 2021, 14:27

So i just did some testing.
Here is the code:
Code: Select all
platform.apilevel = "2.0"

local pww, pwh = 318, 212;

local startTime = timer.getMilliSecCounter();
local curTime = 0;

local tstart = timer.start;
function timer.start(ms)
   if not timer.isRunning then
      tstart(ms);
   end
   timer.isRunning = true;
end
local tstop = timer.stop;
function timer.stop()
   timer.isRunning = false;
   tstop();
end

local functionCalls = {};

function on.resize(w, h)
    pww, pwh = w, h;
end

function on.timer()
    curTime = timer.getMilliSecCounter() - startTime;
    platform.window:invalidate();
end

function on.paint(gc)
    gc:setColorRGB(0);
    gc:setFont("sansserif","r",12);
    local y = 20;
    for i=1, #functionCalls do
        gc:drawString(functionCalls[i], 10, y);
        y = y+15;
    end
    gc:setFont("sansserif","b",24);
    gc:drawString(curTime, (pww - gc:getStringWidth(curTime))/2, pwh/2, "middle");
end

function on.construction()
    table.insert(functionCalls, "construction");
    timer.start(0.01);
end

function on.deactivate()
    table.insert(functionCalls, "deactivate");
end

function on.activate()
    table.insert(functionCalls, "activate");
    timer.start(0.01);
end

function on.enterKey()
    table.insert(functionCalls, "enterKey");
    timer.start(0.01);
    platform.window:invalidate();
end


There was another strange occurence that i discovered during this.
In the emulator the eventcalls are like you would expect: first on.construction then on.activate.
But on my calc it was strange: the first two calls are the same. But then on.deactivate gets called followed by on.activate once more.

Now to the main subject of this thread:
The timer continues if i close the document by pressing the home button and the opening it again. Just like it should. But when i am in the document and turn the calc of with ctrl+home and turn it back on again i see the document for a split second before the home screen is shown. If i open the document now the timer is frozen and won't start no matter what i do. In case the events aren't called I added on.enterKey, which works even when the timer is frozen.The timer only starts working again after completely restarting the script.

My calc is a ti-nspire cx
OS is v4.5.1.12
User avatar
Rankail
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Level up: 64%
 
Posts: 21
Joined: 09 Nov 2019, 18:33
Location: Germany, North Rhine-Westfalia
Gender: Male
Calculator(s):
MyCalcs profile
Class: 12

Re: Nspire-Lua Timer not working after closing and then open

Unread postby jimbauwens » 31 Mar 2021, 14:19

It's been a long time since I experimented with the timer, but I recall some similar experiences, though mostly related to hidden crashes during serialisation (with on.save/on.restore).

Could you try some experiments without the apiLevel directive? It can cause the script to restart if the API level hasn't been set inside the TNS yet. Or, you could try to load the document, save it, close it, re-open it, and see if the behaviour is the same (force saving the document will store the API level details in the XML).

The behaviour with the multiple active/deactive stuff might be related to these script restarts, but regardless they have always odd :)
User avatar
jimbauwensProgrammeur
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Level up: 30.5%
 
Posts: 54
Joined: 13 May 2011, 00:00
Location: Belgium
Gender: Male
Calculator(s):
MyCalcs profile
Class: Computer Science @ VUB University Brussels


Return to Nspire-Lua

Who is online

Users browsing this forum: ClaudeBot [spider] and 2 guests

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1167 utilisateurs:
>1159 invités
>3 membres
>5 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)