Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: MRide on July 16, 2010, 12:35:21 pm

Title: subroutines
Post 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)
Title: Re: subroutines
Post by: calcdude84se on July 16, 2010, 12:44:59 pm
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. :)
Title: Re: subroutines
Post by: Quigibo on July 16, 2010, 01:05:03 pm
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.
Title: Re: subroutines
Post by: MRide on July 16, 2010, 01:41:23 pm
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.)
Title: Re: subroutines
Post by: Builderboy on July 16, 2010, 02:36:06 pm
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?
Title: Re: subroutines
Post by: MRide on July 16, 2010, 07:24:20 pm
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.
Title: Re: subroutines
Post by: calcdude84se on July 16, 2010, 07:59:36 pm
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.
Title: Re: subroutines
Post by: MRide on July 16, 2010, 08:28:34 pm
Yes, It is simply a way of returning to the title screen.  I won't need to go back.  Thanks
Title: Re: subroutines
Post by: DJ Omnimaga on July 19, 2010, 07:00:00 pm
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