Author Topic: Making appvars  (Read 3764 times)

0 Members and 1 Guest are viewing this topic.

Offline Calcman84

  • LV0 Newcomer (Next: 5)
  • Posts: 1
  • Rating: +0/-0
    • View Profile
Making appvars
« 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?

Offline Fast Crash

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 192
  • Rating: +45/-7
  • Virus of tomorrow
    • View Profile
Re: Making appvars
« Reply #1 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 :)

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Making appvars
« Reply #2 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.
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Making appvars
« Reply #3 on: May 05, 2011, 08:50:05 am »
We should add this to the tutorial list, it is very clear I think.
I'm not a nerd but I pretend:

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Making appvars
« Reply #4 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!
« Last Edit: May 05, 2011, 10:02:54 am by Scout »