Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Emerov on April 20, 2012, 03:07:40 am

Title: Using tokens and strings together
Post by: Emerov on April 20, 2012, 03:07:40 am
I'm attempting to access arbitrary OS vars from the calculator, and subsequently delete them. The code works with programs, groups, appvars, and letters, but whenever I try to access the vars represented by tokens, it does not work properly. Basically, I copy the randomly selected var name over into another string so that I can delete it, but the string doesn't seem to recognize the tokens following the first one. Here is my code (simplified):
Code: [Select]
.DELSUB2
Fix 5
"var "->Str3
"ABCDEFGHIJKLMNOPQRSTUVWXYZØ"->Str5
"L1L2L3L4L5L6"->Str6
"  "->Str8
sub(LSD)
Return

Lbl LSD                             //This will only ever delete L1. If the randomly selected number is not 0, then nothing will happen
Copy(rand^6*2+Str6,Str8,2)
DelVar Str8
Return

Lbl ABC                             //This works
Copy(rand^27+Str5,Str3+1,1)
DelVar Str3

Is there a way to get around this lack of string support for tokens? Like, can these variables be accessed via hex code or something? Thank you!
Title: Re: Using tokens and strings together
Post by: Emerov on April 21, 2012, 05:38:52 pm
*Bump* Can somebody help me out with this?
Title: Re: Using tokens and strings together
Post by: Runer112 on April 21, 2012, 06:00:19 pm
It seems that you are operating under the assumption that each list name in the string takes up 2 bytes, but they actually take up 3. The tokens themselves are only 2 bytes, but their names in the VAT are 3 bytes. Tricky, I know. But make Str8 one character longer and adjust the Copy() a bit and you should be all set.



On another note, I'll mention a few tips you could use to make this code smaller. Firstly, the letters and list names are sequential values, so there's no need to look them up from a string. You can just add an offset to the base letter/list name. Secondly, if you're only moving 1 or 2 bytes, just use a normal store, no need to use Copy(). :P

Code: [Select]
.DELSUB2
Fix 5
"var "→Str3
"L₁"→Str8
sub(LSD)
Return

Lbl LSD
rand^6→{2+Str8}ʳ
DelVar Str8
Return

Lbl ABC
rand^27+'A'→{1+Str3}ʳ
DelVar Str3
Return
Title: Re: Using tokens and strings together
Post by: Emerov on April 21, 2012, 06:41:59 pm
Awesome, it works and makes sense now! :)
Title: Re: Using tokens and strings together
Post by: Runer112 on April 21, 2012, 06:48:46 pm
Oops, I just noticed a fatal mistake with my optimization to Lbl ABC; I forgot to add 'A' to the random result to actually make the random result in the range of letters! I fixed it now, so if you already grabbed that code, you should grab the fixed version.
Title: Re: Using tokens and strings together
Post by: Emerov on April 21, 2012, 08:30:37 pm
Oh, I just added E41 and it worked fine. Is the 'A' thing better to use or does it just convert it during parsing?
Title: Re: Using tokens and strings together
Post by: Runer112 on April 22, 2012, 12:24:59 am
They're the same thing. The 'char' notation is more of a convenience/readability feature. The same applies for token values, which can be inserted with Ttoken.