Page 1 of 2

Comment faire une action quand un chiffre est appuyé?

Unread postPosted: 09 Feb 2013, 11:06
by tiganaki
Tout est dans le titre.

Re: Comment faire une action quand un chiffre est appuyé?

Unread postPosted: 09 Feb 2013, 11:08
by nikitouzz
Non il n'y a rien dans ton titre....
-tu as quel calculatrice ?
-tu veux faire ca en quel langages
-tu sais programmer un peu deja ?

(et un "sil vous plait" ne serait pas de trop non plus...)

Re: Comment faire une action quand un chiffre est appuyé?

Unread postPosted: 09 Feb 2013, 11:12
by tiganaki
Je suis dans le forum LUA donc je c'est pour le langage LUA.
Je sais peu programmer.
J'ai une TI NSPIRE CX CAS

Re: Comment faire une action quand un chiffre est appuyé?

Unread postPosted: 09 Feb 2013, 11:20
by critor
Bonjour,

En Lua, pour exécuter une action en fonction des touches pressées, il faut définir la fonction événementielle on.charin(ch).

Code: Select all
function on.charIn(ch)
     if(ch=="1")
          ...
end

Re: Comment faire une action quand un chiffre est appuyé?

Unread postPosted: 09 Feb 2013, 11:25
by tiganaki
merci
ah et une petite question: comment faire pour que le nombre aléatoire (math.random()) ne change pas à chaque fois qu'une touche est pressée.

Re: Comment faire une action quand un chiffre est appuyé?

Unread postPosted: 09 Feb 2013, 11:29
by critor
De rien :)


Tu peux tout simplement enregistrer ce nombre dans une variable en début de programme.

Comme ça, il n'est tiré qu'une fois.

Re: Comment faire une action quand un chiffre est appuyé?

Unread postPosted: 09 Feb 2013, 11:32
by tiganaki
je l'ai enregistré dans une variable mais ça ne change rien

Re: Comment faire une action quand un chiffre est appuyé?

Unread postPosted: 09 Feb 2013, 11:45
by critor
Où fais-tu cet enregistrement?
Si c'est dans une fonction événementielle comme le on.charIn() ou le on.paint(), forcément il est retiré au sort à chaque appel.

Mets-le en tout début de programme hors de toute fonction:
Code: Select all
seed = math.random()


Il ne sera tiré qu'au lancement du programme.

Re: Comment faire une action quand un chiffre est appuyé?

Unread postPosted: 09 Feb 2013, 11:52
by tiganaki
je veux qu'il soir retiré au sort à chaque fois que la touche appuyée est bonne, pas quand n'importe quelle touche est appuyée.

Re: Comment faire une action quand un chiffre est appuyé?

Unread postPosted: 09 Feb 2013, 11:53
by critor
Ben déplace-le dans le test "if" alors.