Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: MRide on July 16, 2010, 12:35:21 pm
-
In Axe, is it possible for a program to call itself?
Maybe put a label at the top of the program, then call it as a subroutine?
ex:
:Lbl AR
Some code
:sub(AR)
-
Welcome to omnimaga!
That is indeed possible, though I'm curious as to what you'd be using it for. (Just asking)
I recommend you introduce yourself in the Introduce Yourself (http://www.omnimaga.org/index.php?board=10.0) subforum. :)
-
Yes, you can have recursive subroutines! It might not work if you are using more than one argument though because all the subroutines share the same temporary variables, you'd have to allocate memory on the fly using free ram. However, I can't think of a routine that would be faster if done recursively. If you want speed, just do some nested loops. Its possible you can get a smaller size than a regular routine though.
-
Thanks. I'm rewriting a BASIC program in Axe, and I can't put the whole section in a loop because the call is inside an if statement. (At least, that's what I remember from programming the game in BASIC.)
-
One thing thats really cool about Axe, is how Goto'ing from inside a while loop or an if statement will *not* create memory leaks, unlike Basic. The only time you have to worry about memory leaks is if you call a subroutine with Sub() and you never Return from it. Out of curiosity, what kind of game are you trying to Port over to Axe?
-
I'm porting a game called Pica-Centro. It's like Master Mind, but with numbers.
So use Goto AR instead of sub(AR)?
That does make more sense.
-
Well, it depends on what you're doing. If I am correct that you need that statement to restart the game if necessary, then yes, a goto should be more appropriate, as you won't need to go back.
-
Yes, It is simply a way of returning to the title screen. I won't need to go back. Thanks
-
I'm happy Axe doesn't cause mem leaks when doing this. In my RPGs, I often wanted to go back to the title screen when dying, but I stopped because it caused memory errors. There are workarounds but they are hard to implement in BASIC