Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: Tape on April 08, 2019, 03:42:01 pm

Title: Help with startTmr and checkTmr
Post by: Tape on April 08, 2019, 03:42:01 pm
I am trying to make a program that detects how many times the user has pressed enter until the timer goes up

(it's not going as planned)

here goes
Code: [Select]
10->V
startTmr->
0->B
checkTmr(A)->X
Lbl 88
If V>=X>=0
Then
0->T
Lbl87
getKey->T
If T=105
Then
B+1->B
If checkTmr(A)>V
Then
goto 88
End
ClrHome
End
If T =/= 105
Then
Goto 87
End
Lbl 89
Disp "Coins Earned:",B
Title: Re: help
Post by: Geekboy1011 on April 08, 2019, 04:07:44 pm
I made some edits to the post for you to move the code into a code block, you can do that with code tags [code] *code here* [/code]The edit button can show you what I mean!
I will take a look at the code some more later but nice to have you on the forum! Maybe someone will get to this before me tho :) We talked on IRC earlier about you possible using IF Then blocks wrong. Have you looked into this yet?
Title: Re: Help with startTmr and checkTmr
Post by: Xeda112358 on April 08, 2019, 04:21:14 pm
There are a lot of issues with the code. An example is that If ... Then need and End
Here is how I would code it:
Code: [Select]
0→C          ;This is our counter
startTmr→T
While checkTmr(T)<10
If getKey=105
C+1→C        ;Since our IF block is only 1 line of code, we don't need a Then... End
End          ;for the While loop
Disp "PRESSED ENTER",C,"TIMES"
Since the If statement only had one line of code, it doesn't need a Then... End


The optimized version looks like:
Code: [Select]
startTmr→T
0
While 10>checkTmr(T
Ans+(getKey=105    ;In BASIC a TRUE statement returns 1, a FALSE statement returns 0. So this adds 1 to Ans when getKey=105
End
Disp "PRESSED ENTER",Ans,"TIMES"
EDIT: Fixed a copy-paste typo, added some comments, fixed title