Author Topic: Data() and appvars  (Read 6609 times)

0 Members and 2 Guests are viewing this topic.

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Data() and appvars
« on: July 21, 2012, 03:38:27 pm »
I've got a list defined in one of my games that stores coordinates. Like this:
Data(10,11,10,21,10,31,10,41,20,11,20,21,20,31
etc. .... 40,31,40,41)→GDB1
The coordinates are for parts of a map. So far I've only got 1, but I want to make more and store them in appvars. And I really don't understand appvars - at all.  :'(
How do I define it with it's length? The list has 32 coordinates, meaning 64 numbers in it. What length is that? Can I do this:
GetCalc("appvAPPVAR",64)
to define it or is that completely wrong?
Once that's done, how do I store the list into it?
And more. Because when I checked the External Vars Tutorial, it just talks about numbers, not lists.
Essentially, can I either be told that it's not possible, or be told a step-by-step-super-detailed tutorial on how to do it?

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Data() and appvars
« Reply #1 on: July 21, 2012, 03:50:27 pm »
It looks like you've pretty much got it, you just need to copy the data into the appvar once its created, like this:

Copy(GDB1,GetCalc("appvAPPVAR",64),64)

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Data() and appvars
« Reply #2 on: July 21, 2012, 03:51:13 pm »
Well, when you create an appvar, you want to direct a pointer to it, like GetCalc("appvAPPVAR",64)→A. That will make it so that pointer A points to the appvar. Then you'd want to copy all the data from your GDB into the appvar. Copy(GDB1,A,64). That will copy 64 bytes from GDB1 into A. (A points to the appvar, so really you are copying it into the appvar) Also hi and welcome here. :)


EDIT: :ninja:
« Last Edit: July 21, 2012, 03:53:07 pm by parserp »

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Data() and appvars
« Reply #3 on: July 21, 2012, 03:55:11 pm »
Thanks!

But shouldn't the size be larger? I don't think you can store a number like 41 in 1 bit. Or byte? EDIT: Byte
Don't you need 8 bits/2 bytes for numbers up to 256?
« Last Edit: July 21, 2012, 03:58:14 pm by dinosteven »

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Data() and appvars
« Reply #4 on: July 21, 2012, 04:00:38 pm »
When you do GetCalc("appvAPPVAR",50), you are creating an appvar with 50 bytes, not bits. You can use the formula (2^#OfBits)-1 to see the range of numbers that a certain amount of bits can hold. Since a byte is 8 bits, it can hold 2^8 -1 = 255 numbers. :) The reason we have the -1 is because we start counting at zero, not 1, so the appvar can hold 256 different numbers, but one of those numbers is 0, so we have the range 0-255. Does that make sense?

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Data() and appvars
« Reply #5 on: July 21, 2012, 04:03:48 pm »
Yeah, that makes sense. For some reason, I thought a byte was 4 bits.
So 1 byte is enough to hold all #s up to 255, right?

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Data() and appvars
« Reply #6 on: July 21, 2012, 04:04:32 pm »
All whole numbers, yes. (You can't store something like 2.5 into 1 byte)

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Data() and appvars
« Reply #7 on: July 21, 2012, 04:30:30 pm »
I tried it, but got an "ERR:MEMORY" even though I still have 9434 bytes of RAM left.
 appvAPPVAR now has size 143.
???

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Data() and appvars
« Reply #8 on: July 21, 2012, 04:33:10 pm »
Was this while compiling or while running?

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Data() and appvars
« Reply #9 on: July 21, 2012, 04:33:32 pm »
While running.

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Data() and appvars
« Reply #10 on: July 21, 2012, 04:34:25 pm »
hm, could you post your code? You may have done something wrong with the other part of the program.

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Data() and appvars
« Reply #11 on: July 21, 2012, 04:47:10 pm »
Code: [Select]
:.A
:"appvAPPVAR"→Str1
:GetCalc(Str1,64)→A
:Data(10,11,10,21,10,31,10,41,20,11,20,21,20,31,20,41,30,11,30,21,30,31,30,41,40,11,40,21,40,31,40,41,50,11,50,21,50,31,50,41,60,11,60,21,60,31,60,41,70,11,70,21,70,31,70,41,80,11,80,21,80,31,80,41)→GDB1
:Copy(GDB1,A,64)

I've got Axe v 1.0.5
And I compiled it for NoShell, running it with BrandonW's Noshell.
But even though it says "ERR:MEMORY", appvAPPVAR appears in the Memory menu with size 79 now. What size is it for you?
« Last Edit: July 21, 2012, 05:15:20 pm by dinosteven »

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: The Game
« Reply #12 on: July 21, 2012, 04:54:10 pm »
It compiles/runs just fine for me... What version of Axe are you using/what shell are you running it from?
« Last Edit: July 21, 2012, 04:54:55 pm by parserp »

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Data() and appvars
« Reply #13 on: July 21, 2012, 05:09:49 pm »
The same size. It still has 64 bytes of data in it, but the extra 15 are for the VAT entry and the name. :)

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Data() and appvars
« Reply #14 on: July 21, 2012, 05:16:28 pm »
So it worked, and my calc's just trolling me by giving me the "ERR:MEMORY". Weird, but it works!

EDIT: No, it didn't. To access it in my game, I stored it to a variable S, since I couldn't use GDB1. After modifying my game to fit S, the map completely disappeared, except for the upper left corner. I assume that everything was changed to '0', and that it was mapping at 0,0
What to do?
« Last Edit: July 21, 2012, 06:42:17 pm by dinosteven »