Author Topic: Writing to the same pointer  (Read 3645 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
Writing to the same pointer
« on: January 01, 2011, 12:40:43 am »
Every time I try to do something like

If L=1
"Test" --> str1
"Stuff" --> str2
If L=2
"Blah" --> str1
"Dude" --> str2

It gives me an error. I think it's because it won't write to the same pointer. I tried putting the str1 and str2 in brackets, but that didn't work either.
In-progress: Graviter (...)

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Writing to the same pointer
« Reply #1 on: January 01, 2011, 12:46:51 am »
When Axe goes to write to the pointer, it first creates it. If the pointer already exists, then it can't create it.Try using Copy( or offsetting your strings instead.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Writing to the same pointer
« Reply #2 on: January 01, 2011, 12:47:36 am »
Yeah, that's not going to work correctly. It's because the axe parser isn't smart enough to know that it can only be one of those.  For all it knows, L could change, causing pointers to be for both of those.  I think if you do a delvar of the variable it should work.

If not, what you need to do is to actually set up a pointer for L1 and L2 at the top to be all 0's as big as you want it +1 byte.  So, if the maximum word or text you are putting in there is 5 bytes, say for "hello", then make it 6 zeros.  Then, instead of storing to the pointer, copy it to the pointer that is already defined.  (I don't know if you can have just text, and I'm pretty sure you can't copy("text",Str1,5), either.

Just remember, if you are doing text, it is null terminated, which means there is a 0 at the end of the text, which is an extra byte.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Writing to the same pointer
« Reply #3 on: January 01, 2011, 12:51:38 am »
(I don't know if you can have just text, and I'm pretty sure you can't copy("text",Str1,5), either.

I was thinking something more along the lines of storing everything to one variable then copying pieces to the RAM areas from it into the needed variables.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Writing to the same pointer
« Reply #4 on: January 01, 2011, 04:26:10 am »
(I don't know if you can have just text, and I'm pretty sure you can't copy("text",Str1,5), either.

That actually works perfectly :) You just need to make sure that any string you copy into Str1 is not longer than the very first string you put into it.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Writing to the same pointer
« Reply #5 on: January 01, 2011, 06:45:43 am »
Static pointers are called static pointers because they're, well... static.  Once you define them, you can't change their value.  This is because once you define something it has to be in memory somewhere.  You can't change where something is in memory without using a copy.  BUT!  Since Axe 0.4.6 you can now do this "almost" automatically by storing them to variable pointers like so:

Code: [Select]
If L=1
"Test"->A
"Stuff"->B
End
If L=2
"Blah"->A
"Dude"->B
End
Disp A,B

This works because the VALUE of the pointer can change, but the place where the data is in ram cannot (without a copy).
« Last Edit: January 01, 2011, 06:46:11 am by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Ikkerens

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 378
  • Rating: +28/-9
  • JavaScript Magician
    • View Profile
    • Walotech
Re: Writing to the same pointer
« Reply #6 on: January 03, 2011, 12:18:21 pm »
Static pointers are called static pointers because they're, well... static.  Once you define them, you can't change their value.  This is because once you define something it has to be in memory somewhere.  You can't change where something is in memory without using a copy.  BUT!  Since Axe 0.4.6 you can now do this "almost" automatically by storing them to variable pointers like so:

Code: [Select]
If L=1
"Test"->A
"Stuff"->B
End
If L=2
"Blah"->A
"Dude"->B
End
Disp A,B

This works because the VALUE of the pointer can change, but the place where the data is in ram cannot (without a copy).
Hail Quigibo,
the life-saver :w00t:

Splut for Android [----------]
Paused/halted indefinitely, might be abandoned, our graphic designer quit and the rest of us simply doesn't have the time to work on it...

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Writing to the same pointer
« Reply #7 on: January 03, 2011, 01:50:05 pm »
Related to this, I think I read somewhere that adding raw data to your program doesn't increase its size, so when I create strings or hex values for sprites, where exactly is would it be stored?
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 Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Writing to the same pointer
« Reply #8 on: January 03, 2011, 02:10:05 pm »
Thats not true, adding raw data does increase the size.  What you may have heard is that it does not effect the size of the executable code, ie: the amount of data might go up but the amount of code will stay the same.  This is important if you are writing a program for MirageOS or Doors.