Author Topic: Storing Levels into an Appvar  (Read 5087 times)

0 Members and 1 Guest are viewing this topic.

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Storing Levels into an Appvar
« on: January 27, 2011, 07:12:59 pm »
How could you store a bunch of levels into an appvar, then read from the appvar to create a temporary variable? The levels are in the format [10240blahblahblah] in hex, and then there are 6 other variables that are tilemap width, tilemap height, starting tilemap x, starting tilemap y, starting sprite x, and starting sprite y.
Any help is appreciated.
In-progress: Graviter (...)

Ashbad

  • Guest
Re: Storing Levels into an Appvar
« Reply #1 on: January 27, 2011, 09:24:15 pm »
Well, the way to actually create appvars is in the form: GetCalc("appvNAME",Size)->Pointer to data.  An example:

Code: [Select]
GetCalc("appvSAUSAGE",1337) -> P
"Daddy would you like some sausauge?  Daddy would you like some sausages" -> Str1
" " -> Str2
Copy(Str1,P,Str2-Str1-1)

Would create appvar SAUSAGE that's 1337 bytes in size and Stores the pointer to the appvar in P.  Then, I simply copied the lyrics of the sausage song into it.  It can be read from like any old pointer, such as doing this:

Code: [Select]
Disp P
...
Displays the song up to the first
occurence of hex code $00, which
was at the end of Str1 that we copied
...

Warning, however, if there's not enough RAM to create the appvar, then it will return 0 into P instead of the actual pointer to the appvar.  So, if we ran the second part, instead of saying "Daddy would you like some sausage..." it would say some random crap like "!@HDFJK*%TNHSKJDFJHSK$^FKJD%$" Until the first occurence of $00.  Here's a way to check for the inability to create an appvar:

Code: [Select]
Return!If GetCalc("appvSAUSAGE")
Which pops the last entry into PC and resumes the flow of the program -- or quits the program if no pushes of PC happened.

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Storing Levels into an Appvar
« Reply #2 on: January 27, 2011, 09:32:56 pm »
Why do you use Str2-Str1-1? Is it because of that empty byte after every string?
In-progress: Graviter (...)

Ashbad

  • Guest
Re: Storing Levels into an Appvar
« Reply #3 on: January 28, 2011, 09:59:57 am »
yeah, but that helps it so disp stops at the empty byte.  I just used Str2 to get the relative size of The sausage song's lyrics.

And there's only an empty byte after strings ending with something like -> Str1.  If there's no static pointer assigned to it, then no extra byte is added.

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Storing Levels into an Appvar
« Reply #4 on: January 31, 2011, 10:10:42 pm »
So here's one of my sample levels - how would you store this into an appvar?

[666666666666666666666666 --> GDB004
[933338666666666666666666
[600000000000000000000006
[600000000000000000000006
[600006666666666666660006
[600009338666933338160006
[600006000000000006060006
[600006000000000006060006
[600000000000000000060006
[600000000000000000060006
[666669333333386666660006
[666666666666666666660006
[600000000000000000000006
[600000000000000000000006
[666666666666666666933338
[666666666666666666666666
In-progress: Graviter (...)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Storing Levels into an Appvar
« Reply #5 on: January 31, 2011, 10:12:32 pm »
Code: [Select]
GetCalc("appvNAME",Size)->A
Copy(GDB004,A,Size)

:D

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Storing Levels into an Appvar
« Reply #6 on: January 31, 2011, 10:53:55 pm »
So if I wanted to put in multiple levels, it would be the same process?
Two questions - the size of the tilemap is half the actual size, right? also, how would I access the appvar contents from the main program?
In-progress: Graviter (...)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Storing Levels into an Appvar
« Reply #7 on: January 31, 2011, 10:59:13 pm »
Not quite the same process.  The copy statement copies it to the beginning of the appvar, since the pointer A is pointing to the beginning.  Once you copy the first level, you will need to increment A by the length of the first chunk of data so you don't overwrite it.  You will also need to make sure that when you create the appvar with the GetCalc() command, you initialize it with enough memory to fit all of your levels.

As for the size... why would it be half?

And as for accessing an Appvar that already exists, you would first get the pointer to the start of the appvar with GetCalc("appvNAME")->P, and then copy your levels from the appvar and to wherever you want with a copy statement.

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Storing Levels into an Appvar
« Reply #8 on: January 31, 2011, 11:03:19 pm »
Oh, okay. I get it now :D
I thought it was half for some arndom reason. I see why I'm wrong now.

To initialize the memory, do you have to use Zeros(?
« Last Edit: January 31, 2011, 11:04:10 pm by leafiness0 »
In-progress: Graviter (...)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Storing Levels into an Appvar
« Reply #9 on: January 31, 2011, 11:32:05 pm »
Oh, okay. I get it now :D
I thought it was half for some arndom reason. I see why I'm wrong now.

You probably figured it out, but each hex digit is one nibble (half a byte) :)

To initialize the memory, do you have to use Zeros(?

Nope, Zeros(42) is exactly the same as [000000000000000000000000000000000000000000000000000000000000000000000000000000000000] (42 bytes of zero, or 84 zeros). Just easier to write ;)
« Last Edit: January 31, 2011, 11:32:25 pm by Deep Thought »




Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Storing Levels into an Appvar
« Reply #10 on: February 01, 2011, 01:32:33 am »
Oh, okay. I get it now :D
I thought it was half for some arndom reason. I see why I'm wrong now.

To initialize the memory, do you have to use Zeros(?

When I say initialize, I mean create the appvar.  The command for that is getCalc("appvName",size)

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Storing Levels into an Appvar
« Reply #11 on: February 09, 2011, 10:37:03 am »
When you create a new Appvar using the GetCalc(NAME, SIZE) command, and the appvar name already exists, it is replaced with a new Appvar of Size bytes that is filled with zeroes.

If you would like to read from an appvar, set a maximum size for the level and then when loading it, copy it to L1 or another saferam area. Then, simply read from L1.

If you want to store multiple levels in the same appvar, store the levelset like this:
1. Name of levelset
2. Number of levels
3. The size of each of the levels
4. Each level in turn
If how to read this levelset isn't self-explanatory, I'll explain it later.

Oh, and that "appv" in the appvar name is actually the [2nd]+[v] token, not simply typing "appv".
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com