Author Topic: subroutines  (Read 4380 times)

0 Members and 1 Guest are viewing this topic.

Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
subroutines
« 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)

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: subroutines
« Reply #1 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 subforum. :)
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: subroutines
« Reply #2 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.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
Re: subroutines
« Reply #3 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.)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: subroutines
« Reply #4 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?

Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
Re: subroutines
« Reply #5 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.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: subroutines
« Reply #6 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.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
Re: subroutines
« Reply #7 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

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: subroutines
« Reply #8 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