Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Calcman84 on May 03, 2011, 03:16:54 pm

Title: Making appvars
Post by: Calcman84 on May 03, 2011, 03:16:54 pm
I am getting along with axe, and am making a game, but I need an appvar, how would I make an appvar as a list and a matrix?
Title: Re: Making appvars
Post by: Fast Crash on May 03, 2011, 03:24:18 pm
Code: [Select]
"appvNAME"->Str1
Getcalc(Str1,SIZE)->P

And then to get each byte(s), use it like :
Code: [Select]
{P} // first byte
{P+1} // second byte
...
{P}r // two first bytes

If you have any other question just ask :)
Title: Re: Making appvars
Post by: Michael_Lee on May 03, 2011, 06:34:41 pm
Let's say that you want to treat the appvar as a matrix with 5 columns and 4 rows.  For the most part, memory in Axe is treated as a list, not a matrix, so we have to use a workaround to be able to use memory as a matrix.

So, we want a matrix.  Because our matrix has sides of 4 and 5, the total amount of memory we want would be 20 bytes (or 40, if you use double-byte numbers).

We can create an appvar like this:

Code: [Select]
"appvNAME"->Str1
GetCalc(Str1,20)->P
You can get the 'appv' symbol by hitting [2ND] then [8].

To write to and access the 5th byte in the appvar, you would do this:
Code: [Select]
42->{P+4}
Disp {P+4}>Dec
(Remember that lists in computers start at zero: to access the 1st byte, do {P}, which is equal to {P+0}, and to access the last, 20th byte, do {P+19}).

However, if we chose to treat the appvar as a matrix, we can.  The appvar won't be changed in any way, all we're doing is changing the way we access it.
I'm going to arrange the bytes in a block.
Code: [Select]
00  01  02  03  04
05  06  07  08  09
10  11  12  13  14
15  16  17  18  19
If we conceptualize the appvar like this, then we can use a short formula-thingy to input the row and column, and return the actual byte we want.

{ROW*LENGTH + COLUMN + POINTER}

So, if we want the byte at column 1, row 2, we would do this:
{2*5+1+P} == {11 + P}
Because this is computers, we treat the first rows/column as the zeroth row/column.


That might be a bit of a complicated answer: let me know if you need anything clarified.
Title: Re: Making appvars
Post by: aeTIos on May 05, 2011, 08:50:05 am
We should add this to the tutorial list, it is very clear I think.
Title: Re: Making appvars
Post by: Munchor on May 05, 2011, 10:01:40 am
If this is for high-scores, take a look at this:

Code: [Select]
:"appvNAME"?Str1       ;Give it a name
:UnarchiveStr1         ;Unarchive it (no problem if it doesn't exist)
:GetCalc(Str1)?T       ;Check if it exists
:!If T                 ;If it doesn't
:GetCalc(Str1,2)       ;Create it (I give it 2 bytes of space)
:0?{T}^r               ;Let's also set 0 to the first 2 bytes
:End

This is me storing 0 to the first two bytes of a bytearray.

Let's say the user beats the highscore, so I do this:
Code: [Select]
500->S                 ;This is the highscore
S?{T}^r                ;Store the highscore in the appvar

I want to display the highscore:

Code: [Select]
Text(0,0,{T}^r>Dec     ;Don't forget the Dec!