I'm basing a Halo RPG (with multiplayer and continually growing storyline) off of tifreak's AOD. However, he uses the "getkey" function to utilize small menus on the right hand of the screen, and although I have studied the getkey part of his program, I can't quite figure out how it works (and how to make the cursor automatically jump 7 lines for each menu item being selected). I tried making a side program with just that (to see what happened), and it didn't ask for input or anything.

So how do you use the "getkey" function, and how do you make a cursor jump around instead of going through every pixel between menu items? Thanks for your time!
The getKey function basically scans the keypad to see if a key was pressed and if it was, it returns the keycode. For example, if I press [2nd], then that function would return 21. Store that to a variable and all you have left to do is put it into an If conditional or an expression.

The code for finding all of the keycodes by the way is:

10*(row on the calculator)+(column on the calculator).

And, in regards to the second part of your question, I don't quite understand. A little explanation?
If you could present the section of code in question, it would be particularly easy to explain what he's doing, but since I think I get the picture anyway, I'll write a bit of code, you tell me if this is what you mean, and I'll then explain it.


Code:
:ClrDraw
:For(X,0,5
:Text(7X,5,"LINE ",X+1
:End
:DelVar XRepeat K=105
:Text(7X,0,">
:getKey->K
:If 4.5=abs(29.5-K
:Text(7X,0,"[3 spaces]
:X+(K=34 and X=/= 5)-(K=25 and X->X
:End
Okay - though I was pretty sure it didn't even wait for me to input a key when I had it in its own program. I guess I'll go back and mess with it more.

In AOD, tifreak made it so when you scroll down the menu list, it jumped to every 7th pixel (so you'd be centered on the menu item).
Beta7 wrote:
Okay - though I was pretty sure it didn't even wait for me to input a key when I had it in its own program.
It doesn't. getKey returns 0 if you pressed nothing, or a non-zero value corresponding to the key if you pressed a key. That's why you need to put it in a loop.

Edit: Here's the unoptimized version of my code:


Code:
:ClrDraw
:For(X,0,5
:Text(7X,5,"LINE ",X+1
:End
:DelVar X
:Repeat K=105
:Text(7X,0,">
:getKey->K
:If K=25 or K=34
:Text(7X,0,"[3 spaces]
:If K=34 and X=/=5
:X+1->X
:If K=25 and X=/=0
:X-1->X
:End
Using an if statement, how do I check whether a list exists?
Beta7 wrote:
Using an if statement, how do I check whether a list exists?
Unfortunately, there's no easy way to do that. You could use one of the Celtic III functions built into Doors CS 7 (for example, GetListElem), but I believe that the pure BASIC method is SetupEditor. My preferred method is this, though (assume your save lists has a fixed size of 6 elements)

1) Checking for save file:


Code:
6->dim(LMINE
If 0=LMINE(1
Then
[do things indicating that there was no save]
End


2) Saving the save file:


Code:
6->dim(LMINE
1->LMINE(1
[store to the other elements as necessary


Makes sense? If in (1) the line 6->dim(LMINE) creates a new list, then element 1 will contain 0.
Makes sense. I'll put it in and move on the rest of the main menu (then I have to figure out how to make the main part of the game Razz).

I have the following in my code:


Code:
Lbl 1
If N=/=(92 or 93 or 94 or 82)
Then
Goto 1
End
If N=/=92
Etc etc etc


The program just loops without exiting the goto loop when you press a legitimate key. Why? And how do I fix it?
So basically you want to minimize your use of Lbls and Gotos as much as possible by using For(), While(), and Repeat() when possible. Another thing is to never, ever Goto from inside a Then/End, because that creates something called a memory leak, wherein the TI-OS will be remembering that it needs to find the Then's End (but of course never will). It will keep remembering more and more Thens for which it has never seen an End, your program will get slower and slower, and eventually you'll run out of memory (ERR:MEMORY). One possible solution:

Code:
Lbl 1
If [condition]
Goto 1
If N=/=92
Etc etc etc
Notice that you may omit the Then/End if you have only a single statement being conditionally executed.

Another problem is your =/= statement; it is invalid. What you have basically said is this:


Code:
If N=/=1
(etc)
'or', 'and', 'xor', and 'not(' are Boolean operators, meaning that they can only return 0 or 1. '4 or 5' is 1. '4 or 0' is 1. '4 and 5' is 1. '4 and 0' is 0. See? What you want to do is this:


Code:
If N=/=92 and N=/=93 and N=/= 94 and N=/=82
(etc)
(92 or 93 or 94 or 82) isn't what you want. It evaluates the 92 separately from the rest of the expression and finds that it is nonzero (TRUE). (In the context of TI-BASIC, "true" evaluates to a real value of 1.) It then goes on to evaluate the 93, which is also TRUE.

After this, it compares the two TRUE values using an "or" operator to generate yet another TRUE. String a bunch of these together, and the whole right hand side evaluates to 1. In essence, the If statement you wrote is asking whether N isn't equal to 1.

You're looking for If N≠92 and N≠93 and N≠94 and N≠82. But I have to ask, where in that loop is N given a chance to change its value? Nothing is being stored to it in there; you would have to add getKey→N.

BUT. Whenever you Goto to jump outside of an If-Then-End block, you don't give the interpreter the satisfaction of no longer having to search for the End which closes the block that it entered! It just keeps on looking. And when you enter the same block over and over again, eventually it will crash. This is because the interpreter has to keep tabs on how many times it enters the block in order to know how many times it needs to be closed, and only so much memory is allotted.

Anyhow, there are commands that do this looping behavior for you; Goto is generally used to leap somewhere far, far away in the program with the utmost disregard for the natural flow of the program. That all said, see if you can warm up to the following:

Code:
Repeat N=92 or N=93 or N=94 or N=82
getKey→N
End
If N=92
Disp "[1]
If N=93
Disp "[2]
...
Okay, fixed the load saved game part. Thanks!

Now I need help with how to make maps for the homescreen (using matrices). Any takers? Razz
Beta7 wrote:
Okay, fixed the load saved game part. Thanks!

Now I need help with how to make maps for the homescreen (using matrices). Any takers? Razz


I will, I will edit this post with a simple code here shortly.

Edit: I changed my mind, I am going to make a tutorial, and then link you to it after it is done. Very Happy

Here is the tutorial Link, I hope it helps you, and hopefully many others in time.

Homescreen Collision Detectection using Matrices Tutorial
I have yet another question. Razz

I ran into a memory error, which got me thinking - how big can I let my program get? So I started looking around in random menus to see if there was anything I could do to reduce size, and I came across the "list->matrix" and "matrix->list" commands. I tried storing lists in matrices, but couldn't get a matrix to hold anything past 1 column.

So I was wondering - is it possible to store a list in a matrix column other than column 1? How? And, if I'm going to be using a lot of maps, can I store more than one 8x16 map matrix in one matrix, and then call on specific sections of said matrix for that specific map? If so, how?
Beta7 wrote:
I have yet another question. Razz

I ran into a memory error, which got me thinking - how big can I let my program get? So I started looking around in random menus to see if there was anything I could do to reduce size, and I came across the "list->matrix" and "matrix->list" commands. I tried storing lists in matrices, but couldn't get a matrix to hold anything past 1 column.

So I was wondering - is it possible to store a list in a matrix column other than column 1? How? And, if I'm going to be using a lot of maps, can I store more than one 8x16 map matrix in one matrix, and then call on specific sections of said matrix for that specific map? If so, how?


Post the code if you don't mind, it might end up being a memory leak.

And please elaborate on what you mean for the matrices, it sounds like a good idea.
Well, in tifreak's AOD, he had to list out (in a rather large program, I might add Razz) all the stats for all his NPC's. I was wondering if it was possible to store up to 99 stat lists in a matrix (1 list per column), then call upon a specific column for the stats needed. As for the maps, I just thought it might be possible to store more than one map per matrix by using more than an 8x16 matrix and then just calling on the specific area you needed (not to mention the fact that you could have some maps share matrix columns/rows to save even more room).

As for SC, I'm on my phone right now and can't get on my computer until morning. I'll post it tomorrow sometime.
Beta7 wrote:
Well, in tifreak's AOD, he had to list out (in a rather large program, I might add Razz) all the stats for all his NPC's. I was wondering if it was possible to store up to 99 stat lists in a matrix, then call upon a specific column for the stats needed. As for the maps, I just thought it might be possible to store more than one map per matrix by using more than an 8x16 matrix and then just calling on the specific area you needed (not to mention the fact that you could have some maps share matrix columns/rows to save even more room).

As for SC, I'm on my phone right now and can't get on my computer until morning. I'll post it tomorrow sometime.


Well the only way that doing matrices like that will save space will be if you can use areas more then once like you said, as for making it only display 8x16 in larger maps, try:


Code:
:(starting X in Matrix)->X:(starting Y in Matrix)->Y  //Sets the starting location
:For(A,X,X+8
:For(B,Y,Y+16


That way it is always an 8x16 displayed, and will always work if the matrix is 8x16 or bigger.
No, you would save tons of space by not listing out, in brackets, each creature's stats, then setting those equal to a certain list. One 10x1 matrix is 18 less bytes than listing out ten 0's and storing them as a list. Multiply that by a lot of enemy types/varoations and you've got a ton of space saved.
Beta7 wrote:
I have yet another question. Razz

I ran into a memory error,
I'm sure it was a memory leak. Smile Unless you managed to create several 99x99 matrices.
Beta7 wrote:
which got me thinking - how big can I let my program get? So I started looking around in random menus to see if there was anything I could do to reduce size, and I came across the "list->matrix" and "matrix->list" commands. I tried storing lists in matrices, but couldn't get a matrix to hold anything past 1 column.

So I was wondering - is it possible to store a list in a matrix column other than column 1? How? And, if I'm going to be using a lot of maps, can I store more than one 8x16 map matrix in one matrix, and then call on specific sections of said matrix for that specific map? If so, how?
One random thought based on my extensive experience as an ASM programmer trying to tame the TI-OS into quiescence: One element in a list takes up exactly the same amount of memory as one element of a matrix. Any size difference between an NxM-element matrix an an NM-element list are simply the result of a constant difference in their respective headers. However, there are lots of tricks for compressing matrices and lists, including using bound-range integers (for example, numbers that can only be 00 through 99) and packing them into single 9-byte list/matrix elements (eg, 1234567890 -> 12, 34, 56, 78, 90). There are also techniques to pack lists into a virtual 2xN array using complex instead of real numbers, but this doesn't actually save you any space, since complex lists and matrices are 18 bytes per complex element as opposed to 9 bytes per real element.
But KermM, what about if it's just a bunch of stats that would normally be sitting in brackets, waiting on an if statement to store them as a list? A program with the matrix having the stats is 18 bytes shorter than when the stats have to be listed out with commas and then stored to a list (when there were 10 elements that were all 0).

So instead of having a huge program list out in brackets every creature's stats, you just have 1 matrix that contains all the stats.

:Matrix->List([A],4.L2

Versus

:{3,8,15,4,2,13,10->L2
In that case, yes, the actual code to store the data would indeed be smaller. Smile I was referring to the space that the actual List or Matrix takes when it is in memory, separate from whatever programmatic code is necessary to generate the particular data structure.
  
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.

» Go to Registration page
Page 1 of 3
» All times are UTC - 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

 

Advertisement