» Goto page 1, 2  Next
I missed this for so long, and I called myself some bad names.

Anywho, here is a restrictor code when adding things like items for games, etc. This was figured out while porting AOD to the 82, since I want to make it available for most z80 calcs.

Here is the code:

L1(1)+(L1(1)<99)->L1(1

This removes all need for If L11>99:Then:etc...
I really, really hope it was SourceCoder that helped you find that...
Umm... sorry, I figured it out on my own. B)

I will try to post some more tommorrow...
lol...that is pretty 1337 though. Y'know what would be cool? If we could draft up an issue of the newsletter tomorrow. If you write that up, one or two people throw together reviews, and someone write about expr(), I'll write about SourceCoder and some kind of revival article.
Write what up, what the code is, what it could be used for, and why it works?
Exactly, it doesn't have to be that long. Just talk about why you need it, the unoptimized way to do it, the right way to do it, why it works, and what it does.
Ok, I might make it more generalized, but I will try to have it done in the morning...

Also, look in the Links for asm page topic. I would appreciate it...
OK, that works. I'll try to do my stuff tomorrow morning then.
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
Here's a goodie for you I found. Try this:

Code:
```randInt(-10,10)-->X "ClrDraw:Horizontal" + X -->Str9 expr(Str9```

Pretty nifty, no?
Looks cool. You should add it to it.
What's cool is that expr is the key to dynamic coding, you can even make an... omg I just realized
YOU CAN MAKE A BASIC editor in BASIC!!

:Input "PROGRAM::::::::",Str9
:expr(Str9

!!!
Umm, when I execute that program, it just displays 0, and stores the string... Am I missing something?
As far as I know, you can execute commands in strings with expr...
Most commands, except prgm... If that would work, it would make for some interesting coding...

I will be back on line later this evening, got to go do some work...
OK, same here.
Out of curiousity, why do I never see you on aim?
Because I don't have any type of chat program or client on my computer.

I am gonna try to write up a review on Tanks 89 later when I get some time...
KermMartian wrote:
What's cool is that expr is the key to dynamic coding, you can even make an... omg I just realized
YOU CAN MAKE A BASIC editor in BASIC!!

:Input "PROGRAM::::::::",Str9
:expr(Str9

!!!

Seems kind of self-defeating given expr('s limitations.
Do you have anything to add to the expr( or the End of If parts of the article, JPez?
Well it's not really the end of If, just cases where If determines if an arithmetic operation is to be carried out. (After all, I did include something like this in the 1337 guide.) However, that list of lists thing with expr( is really clever, I like it a lot!

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» Goto page 1, 2  Next
» All times are GMT - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum