Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Yeong on September 15, 2011, 11:40:58 am

Title: Routine for quick responce button?
Post by: Yeong on September 15, 2011, 11:40:58 am
How do I write a routine so that if I press the correspond button, do something and if I don't press it, do other thing?
Title: Re: Routine for quick responce button?
Post by: Hayleia on September 15, 2011, 11:43:27 am
The following would work, If I understood well the question (spaces are not needed, just to see better).

Lbl (name)
   If getkey(the number)
      commands
   Else
      commands
   End
Return
Title: Re: Routine for quick responce button?
Post by: Xeda112358 on September 15, 2011, 11:43:58 am
I don't code in Axe, but it might be something like this:
Code: [Select]
If getKey(*key*)
Then
<<code if key is pressed>>
Else
<<code if key isn't pressed>>
End
Again, I don't know if this will work :/
Title: Re: Routine for quick responce button?
Post by: Hayleia on September 15, 2011, 11:45:26 am
I don't code in Axe, but it might be something like this:
Code: [Select]
If getKey(*key*)
Then
<<code if key is pressed>>
Else
<<code if key isn't pressed>>
End
Again, I don't know if this will work :/

This will not work, as "Then" is not an Axe token, but the idea is here, in my opinion.
Title: Re: Routine for quick responce button?
Post by: Xeda112358 on September 15, 2011, 11:46:23 am
Cool, thanks! I need to learn Axe sometime XD
Title: Re: Routine for quick responce button?
Post by: Yeong on September 15, 2011, 11:46:37 am
I forgot to mention timer XP
So, I'll rephrase the question(This happens a lot to me these days)

How do I write a routine so that if I press the correspond button in certain amount of time, do something and if I don't press it, do other thing?
Title: Re: Routine for quick responce button?
Post by: Fast Crash on September 15, 2011, 11:49:46 am
Should work

Code: [Select]
0->A
...
If getkey(key)
A+1->A
Else
0->A
End
If A=(your_timer)
commands...
Else
other commands...
End
Title: Re: Routine for quick responce button?
Post by: Xeda112358 on September 15, 2011, 11:50:48 am
Code: [Select]
time→C                          ;example:   1000→C
!While C*getKey(*key*)
C-1→C
End
If C
   <<code if key is pressed>>
Else
   <<Code if key isn't pressed>>
End

I think this will work, again, i am not sure XD
Title: Re: Routine for quick responce button?
Post by: Yeong on September 15, 2011, 11:58:13 am
Thanks, but why do I multiply C with getKey?
can you explain it for me?
Title: Re: Routine for quick responce button?
Post by: Fast Crash on September 15, 2011, 11:59:37 am
If C=0, the loop will exit (if the key is still pressed).
Title: Re: Routine for quick responce button?
Post by: Yeong on September 15, 2011, 12:00:19 pm
ok. thanks for the explanation.
Title: Re: Routine for quick responce button?
Post by: Xeda112358 on September 15, 2011, 12:00:38 pm
Oops, I just realised that won't work. Let me rethink this...
Title: Re: Routine for quick responce button?
Post by: Fast Crash on September 15, 2011, 12:01:55 pm
lol indeed, it should be !If C in the test under the While loop.
Title: Re: Routine for quick responce button?
Post by: Xeda112358 on September 15, 2011, 12:06:08 pm
let me see...
We want to exit the loop if the key is pressed or time reaches 0.

so just do !While C=0+getKey(*key*)

C=0+getKey(*key*) is only 0 if the key isn't pressed and C is not 0
If C is 0 or the key is pressed, the result is 1
We test for C because if it is 0, it means time ran out. So we do use If C
Title: Re: Routine for quick responce button?
Post by: Fast Crash on September 15, 2011, 12:10:23 pm
It will stay in the loop all the time if he doesn't press the key right ?
Title: Re: Routine for quick responce button?
Post by: Xeda112358 on September 15, 2011, 12:11:14 pm
Not the last one. The loop will exit if he presses the key or time runs out :)
Title: Re: Routine for quick responce button?
Post by: Fast Crash on September 15, 2011, 12:12:59 pm
Code: [Select]
!While C=0+getKey(*key*)So in the beginning C=0 returns 0 and getkey(key) returns 0 and !While continues if the condition is false right ?

EDIT : Er I see what you mean didn't see the C-1->C in the loop.
Title: Re: Routine for quick responce button?
Post by: Xeda112358 on September 15, 2011, 12:14:32 pm
I believe so... Again, I have never used any of this in Axe, so I am not sure. I just remember reading a tutorial for 2.4 or something like that and I am pretty sure that is how the math and While loops work :)
Title: Re: Routine for quick responce button?
Post by: Yeong on September 15, 2011, 12:21:37 pm
Thanks for the help :D
I got the routine working XD
Title: Re: Routine for quick responce button?
Post by: Xeda112358 on September 15, 2011, 12:22:08 pm
Cool! Also, you almost have 1000 posts!
Title: Re: Routine for quick responce button?
Post by: Yeong on September 15, 2011, 12:23:04 pm
I relised XD
*Yeong can't wait to display his custom title under his nickname