Page 1 of 3

[TI BASIC] Subroutines and unarchiving in BASIC

Posted: Wed 19 Oct, 2005 6:05 pm
by CompWiz
Is there any way to archive/unarchive BASIC programs on the calculator from a BASIC program?
Also, If I want to use subroutines in a program, do I have to make a new program to contain each subroutine?
I am working on adapting an old BASIC adventure game skeleton to TI basic as you can read in the announcing projects forum.

Edit kv83: Added tag.

Re: Subroutines and unarchiving in BASIC

Posted: Wed 19 Oct, 2005 6:32 pm
by kalan_vod
CompWiz wrote:Is there any way to archive/unarchive BASIC programs on the calculator from a BASIC program?
Also, If I want to use subroutines in a program, do I have to make a new program to contain each subroutine?
I am working on adapting an old BASIC adventure game skeleton to TI basic as you can read in the announcing projects forum.
Well there is to ways you can do this
-Use zcopy to copy the program into a new one called ztemp
Or
-Run the program directly from the archive using flash Gordon (which is the best option IMO.

As for the sub routine, you make the sub in a new program and when you want to use it you just call the prgm in the main one.

Code: Select all

Example:
MAIN
:Pause "Hi Where Is Sub?
:prgmSUB
:Pause "There It Is!

SUB
:Pause "I'm Right Here ^.^

So you run prgmMAIN and it displays "Hi Where Is Sub?", then you press enter. It calls prgmSUB and it displays "I'm Right Here ^.^", then you press enter. Now it returns to prgmMAIN, and displays "There It Is!".

Sorry if you understand this already, but if not I hope this makes sense :D.

Posted: Wed 19 Oct, 2005 6:58 pm
by CompWiz
Yes, I know how to use programs as subroutines, but I was hoping to not have a whole lot of little subroutine programs. Thanks for the help with archiving. :)

Posted: Wed 19 Oct, 2005 9:07 pm
by KevinJB
Trick the basic interpreter into executing code in a for loop and return when it hit's the end. This might leak ram, I dunno. I've done it before. Something like:

Code: Select all

for (a,0,1)
If A
Goto Z
End

...

Code: Select all

Lbl Z
<sub code>
End
Something like that... :roll:

Posted: Wed 19 Oct, 2005 9:53 pm
by kalan_vod
Yeah it leaks pretty bad, but well just check UTI for that topic.
http://www.unitedti.org/index.php?showtopic=3629

Posted: Wed 19 Oct, 2005 11:32 pm
by CompWiz
Yeah, I read that post on UTI a few days ago. I don't want my program to grind to a halt after a little while.
Another question, is there any way to package several programs into a group and then have a basic program ungroup them when it is used? Also, is there any way to delete programs in basic?

Posted: Thu 20 Oct, 2005 12:34 am
by KevinJB
Oops, that should be not(a instead of A (test if it equals zero not one ;)).

Indeed, it leaks tremoundously. I had found away to do it without them- wish I could remember :(.

And yes, I know what leaks are and how they occur.

PS: Want to see a easy example of what leaks can do?

Code: Select all

Lbl 0
For(A,0,1
If not(A
Goto Z
End
Disp "Bye
Goto 0
Lbl Z
Disp "Hi
End
Note the initial speed, then let it run for about two minutes. If you haven't recieved an 'Error! Memory' message by then; you'll at least notice the crawl it has been reduced too :-)

Posted: Thu 20 Oct, 2005 3:40 am
by threefingeredguy
I posted how to use subroutines in your post about your TBA

Posted: Thu 20 Oct, 2005 4:35 am
by Gambit
Not sure if this has been brought up due to this topic appearing everywhere on various forums/threads, but I used a technique I found on ticalc.org ('cause I didn't want to think of one myself):

http://www.ticalc.org/archives/files/fi ... 14542.html

Considering its age (Sat Sep 2 19:36:55 2000! :o), it was (or may still be) pretty "advanced" concepts :wink:

Posted: Thu 20 Oct, 2005 7:03 pm
by CompWiz
That looks like a good document(expecially for me, as I am terrible at optimizing for speed and size). I'm not sure if that method for subroutines will work for what I am doing, but I'll look into it. Thanks for all the help! :D

Posted: Fri 21 Oct, 2005 12:26 am
by DarkerLine
A good document, but outdated - there are many more known ways to optimize now. Example:
then wrote:{Ans,0
While Ans(1
{Ans(1)-1,Ans(2)+1/(4Ans(1)-3)-1/(4Ans(1)-1
End
Disp Ans
now wrote:{Ans,0
While Ans(1
Ans-{1,2/(16Ans(1)^2+8Ans(1)-3
End
max(Ans

Posted: Fri 21 Oct, 2005 2:13 am
by CompWiz
well once I finish, I'll be sure to upload the source code so you can optimise to your hearts content :lol:

Posted: Fri 21 Oct, 2005 9:11 am
by kv83
Please use the tag.

Posted: Fri 21 Oct, 2005 8:20 pm
by CompWiz
kv83 wrote:Please use the tag.
sorry, tag? :?: :?

Posted: Fri 21 Oct, 2005 9:43 pm
by KevinJB
[TI-BASIC]

He edit's it in to the topic title because he's a 'Nice Guy' apparently :). For future reference, you should include it in all your topics in the Programming Help category.