The End of " If "
Boolean logic, as most BASIC TI programmers understand it, is comprised of an If statement, the 'compared variables' (whether simple (If A=1) or complex (If A=1 and (T>C^D*S/Q+P or G<H+C^D*W)), Then statement for those times you need boolean to perform multiple tasks, the command(s), and the End command, if Then is used.
Since boolean logic is simply "true" or "False" (or 1 or 0 in the calculators case), we can use this to our advantage when writing complex looking code, when in fact, it is so simple, that you will wonder why you didn't figure it out yourself.
The simplest example I can provide would be a 'restricter' routine that restricts the amount of items a character can have in a game, like restricting the amount of potions in an RPG. Z will be where the amount will be stored, and we want it to be restricted to 5. Please make sure you delete variable Z, or store 0 to it, so you understand this next part.
Type the following onto the homescreen of your calculator:
Code: Z+(Z<5)->Z
Now press ENTER repeatedly. It should count up til 5, then just keep displaying 5 afterwards. This is because this is what the calculator sees while Z<5:
Code: Z+(1)->Z
But once Z=5, the calculator begins to see:
Code: Z+(0)->Z
That is why it stops incrementing. This can also be used in more complex routines, like getkey codes:
Say we are storing A and B as row and column for homescreen character movement, and K will be the getkey variable.
Code: A-(((K=25)+(A>1))-((K=34)+(A<8)))->A
B-(((K=24)+(B>1))-((K=26)+(B<16)))->B
In this instance, (Looking at the top one, the bottom is basically the same) we are using the addition and subtraction instead of and or or commands. This also takes into account that you cannot subtract a negative, which is why the second part works. If you notice, A-((( that there are three starting parenthesis, the first is because we have to keep the main engine in one spot, this keeps the calculator from getting confused. The second starts the check to see if it will be able to go up. The confusing thing is the ((K=25)+(A>1)) part. Since these were wrapped in parenthesis as well, the calculator will see the = and > and 'understand' that a conditional is being tested, so will 'know' that + means that both most be true, otherwise, it is a no go.
That may not be the best way to describe that function, but that basically is how it works. As long as you know how to make the code work in the game, who cares what the calc sees, right? :-)
Understanding expr(
expr( can be a very powerful command, if used properly. Simply put, it takes whatever is in a string, and executes it. Sadly, it does not execute program, which would be really nice...
But one interesting feature that I have found is lists. With a lil ingenuity, you can make it look up a list of lists that are stored in a string, and execute a particular bit of it, just by manipulating a couple of variables!
Create 4 lists, LBLAC, LAPPL, LAPES, and LDONE. Give them all the dimension of 20, and fill in with random numbers. Now when you are done with that, create a program, call it anything you like, and put in the following:
Code: :"BLACAPPLAPESDONE"->Str0
:5->X
:1->A
:expr("20+'L'+sub(Str0,A+4,4)+"(X"
Now run the program, and see how it worked. :-) You can of course change the value of X, and see how it effects how it runs. If you want to access the first list, you will need to start with -3, and work up in increments of 4. The above will only work for lists that are all the same name size. Trying to mix sizes will give a syntax error.
Play around with it a bit, you will eventually figure out some other cool ways to put this in a game. :)
Feel free to edit, Kerm. I made this at 1 in the morning... lol