Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Omar Chehab on December 02, 2013, 01:51:23 pm

Title: Help Request - ERROR INVALID TOKEN
Post by: Omar Chehab on December 02, 2013, 01:51:23 pm
I recently started using Axe for my TI programming. I read the manual and the commands files and still could not get an answer. Upon compiling my program, it gives an error saying invalid token.

The error is at ":8*(randInt(1,8)+2)→A" and I am guessing that the line after that too is wrong. In TI basic randInt( generates a number between a range though in axe it is not accepting randInt( as a command. So my question is:

What can I use to replace or fix randInt( as I want to generate a random number in a given range.

* * *

:8*(randInt(1,8)+2)→A
:8*(randInt(1,4)+2)→B→C
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: turiqwalrus on December 02, 2013, 01:55:55 pm
First of all, I believe you can optimise the randInts a little bit, seeing as you can just change the paramaters.

Besides that, →B→C doesn't work, from what I remember, since storing things isn't nestable.
Changing it so that it might work, though, we'd end up with this:
Code: [Select]
:8*randInt(3,10)→A
:8*randInt(3,6)→B:Ans→C
Of course, my own basic skills being rusty, to say the least, there's probably ways to make this even smaller ;)
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: Omar Chehab on December 02, 2013, 02:01:33 pm
Even after fixing what you told me the error still occurs, so I am certain that the error invalid token is caused by the randInt( command.
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: ben_g on December 02, 2013, 02:02:51 pm
nesting stores does work in axe, but I don't think the randint does. Instaed of doing randInt(1,8)+2, you can do rand^8+3. rand in axe generates a random 16-bit number, ^ calculates the remainder of a division by 8 which makes in the range of 0-7 (it doesn't mean power in axe!), and the +3 adds 3 to it to give you the correct range.
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: Omar Chehab on December 02, 2013, 02:11:44 pm
Thank you for the quick reply. Your answer was very informative it fixed my error, though can you please explain what the ^ is if it's not power?
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: ben_g on December 02, 2013, 02:13:54 pm
It's the modulus operator. This is basically a divide, but instead of the quitient of the division, it returns the remainder. Usually, programming languages use the per cent sign (%) for this, but as it's quite hard to get on an 83+ line calculator, axe uses the ^ instead.
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: Streetwalrus on December 02, 2013, 03:57:50 pm
And by the way very few languages have a power operator (Python has ** but most languages have a pow(number, power) function in the advanced math library).
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: Matrefeytontias on December 02, 2013, 04:49:47 pm
Don't know why noone said that already : Axe doesn't have a randInt( routine. If you want randInt(X,Y), do rand^(Y-X)+X instead.
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: Hayleia on December 02, 2013, 05:09:32 pm
You are missing a +1 in the Y-X, otherwise, randInt(0,1) would be rand^1+0 which always returns 0 ;)
Also, while yours gives the general solution, the particular solution was given in ben_g's first post.
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: ClrDraw on December 02, 2013, 10:33:35 pm
It can be annoying getting used to the little things Axe does funny but stay with it and it will get way easier. The only thing that still bugs the crap out of me is the lack of negative numbers...  :w00t:
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: Omar Chehab on December 02, 2013, 10:35:36 pm
Thank you, all!
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: TheMachine02 on December 03, 2013, 04:56:05 am
It can be annoying getting used to the little things Axe does funny but stay with it and it will get way easier. The only thing that still bugs the crap out of me is the lack of negative numbers...  :w00t:

err.. negative number in axe does exist, they just a little different that we expect. As we work with 2 bytes number, negative number start from the highest value possible, and then progressively decrease (well, idk if I am very clear) : some code :

Code: [Select]
-1->B   //this is a correct syntax

//now B=65535
Disp B>Dec,i
//and you can do :
B*8->B
Disp B>Dec,i
//B still negative !
//B=65528   (-8)
B*-1->B    //we now get a positive number
Disp B>Dec,i     //B=8

in fact on two bytes we can code  number from -32767 to 32768 using this method (who is implement in axe)
You may find that if the multiplication is signed, the division (/) is not. However it exist a signed division (it's the // symbol)
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: ClrDraw on December 03, 2013, 08:37:28 am
True I should have cleared up. I meant how confusing it can be using negative numbers. Especially how with regular variables, -1 is 65535 but with variables in L1 its 255... I had to mess with all that in my game blox (http://ourl.ca/20214).
But thank you I didn't know the division thing  :)
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: TheMachine02 on December 03, 2013, 11:17:40 am
it's pretty strange then  :o  cause if you use variable in L1 you have exactly the same thing than with  a normal var (it's just a memory location in all case). Can I see some problematic code please ?
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: Streetwalrus on December 03, 2013, 01:16:17 pm
With one byte values in memory you have to use signed{} to convert 8 bit and 16 bit signed numbers. Actually the way signed numbers work in Axe and ASM is called two's complement which is a particular way to code negative numbers and have them usable exactly like positive ones with the same operations (due to the way modular math works). I hope I make sense. If not, look it up on Wikipedia. ;)
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: Hayleia on December 04, 2013, 12:40:38 am
For your "variables in L1", just store them in two bytes instead of one (using r) and you'll get the exact same results than with "regular variables" and with custom variables.
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: ClrDraw on December 04, 2013, 10:46:00 am
Quote
it's pretty strange then  :o cause if you use variable in L1 you have exactly the same thing than with  a normal var (it's just a memory location in all case). Can I see some problematic code please ?
It's untested, but this is the idea.
Code: [Select]
:Fill(L1,20,0)
:{L1}--
:Disp {L1}>Dec
:0->A
:A--
:Disp A>Dec

Quote
With one byte values in memory you have to use signed{} to convert 8 bit and 16 bit signed numbers.
Cool, I'm looking that up now.

Quote
For your "variables in L1", just store them in two bytes instead of one (using r) and you'll get the exact same results than with "regular variables" and with custom variables.
I didn't use ^r though.
Title: Re: Help Request - ERROR INVALID TOKEN
Post by: TheMachine02 on December 04, 2013, 10:53:32 am
that understandable then, cause your reading and writing an one byte variable. With signed{ or the use of two bytes number, evrything work fine  :)