Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: leafy on January 01, 2011, 12:40:43 am

Title: Writing to the same pointer
Post by: leafy 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.
Title: Re: Writing to the same pointer
Post by: AngelFish 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.
Title: Re: Writing to the same pointer
Post by: jnesselr 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.
Title: Re: Writing to the same pointer
Post by: AngelFish 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.
Title: Re: Writing to the same pointer
Post by: Builderboy 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.
Title: Re: Writing to the same pointer
Post by: Quigibo 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).
Title: Re: Writing to the same pointer
Post by: Ikkerens 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:
Title: Re: Writing to the same pointer
Post by: Michael_Lee 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?
Title: Re: Writing to the same pointer
Post by: Builderboy 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.