Hello to this community. Please first ask in the forum for help the next time, before you create a wiki page ;)
As you wrote, you only were knowing TI Basic for two hours, when you programmed this, which is a quite short time to learn a programming language, but there are still many easy to workaround problems in your code:
:1→Y
:0→D
:0→E
:8→A
:Lbl G
:A-1→A
:getKey→K
:If K=25
:Y+1→Y
:If not(K=25
:Y-1→Y
:End
:randInt(2,7)→D
:If A<1
:8→A
:D→E
:End
:Output(A,1,"H")
:Output(A,2,"H")
:Output(A,3,"H")
:Output(A,4,"H")
:Output(A,5,"H")
:Output(A,6,"H")
:Output(A,7,"H")
:Output(A,8,"H")
:Output(A,E," ")
:Output(A,E+1," ")
:Output(3,Y,"O")
:If A=3
:Then
:If not(Y=E or Y=E+1
:Output(100,100,"P")
:End
:Goto G
As you are quite a newbie to Basic, I wont go into much details yet, but there are some simple things to optimize:
- First of all learn to use For( loops, they will become quite handy, when algorithmically processing the same commands on different objects:
:Output(A,1,"H")
:Output(A,2,"H")
:Output(A,3,"H")
:Output(A,4,"H")
:Output(A,5,"H")
:Output(A,6,"H")
:Output(A,7,"H")
:Output(A,8,"H")
Using For( this will become shortened to:
:For(I,1,8 //Note that you dont have to close parenthesis if you are at the end of an line
:Output(A,I,"H //the same for closing literal string signs
:End
- Also learn to use If statements the right way:
:If K=25
:Y+1→Y
:If not(K=25
:Y-1→Y
:End
First note that when not putting an Then after the If, you also dont have to „End“ the If code block. If you dont put a Then after the If, the compiler, or more likely in TI Basic the Interpreter automatically knows that only the one following line of code belongs to the If.
Though I would do it in a complete other way, you can use Else here to achieve the same effect (Else gets executed, when the previous If expression got the boolean value False):
:If K=25
:Then //Else can only be used if there was a Then
:Y+1→Y
:Else
:Y-1→Y
:End //Now you really need the End, because you used a Then
There are many other things to change here, but I think it is enough for that purpose for now, but let me give you another short advise: Only use Goto structures when you really need to, the alternative While or Repeat loops have the same effect of jumping in code, but will make your programming habit a lot better. Goto structures are often referred to as spaghetti programming and will make your hairs gray, when trying to get the sense of some huger programs back into your mind, that were programmed earlier.
Wake me, when you need me.