In some other BASIC languages I’ve used, there has been a way to jump from a label to another one and then return to the first label.

Example:

Code:

LABEL 0
IF BUTTON()==16 THEN GOSUB LABEL 1
GOTO LABEL 0

LABEL 1
PRINT “HELLO”
RETURN
END


The gosub command would go to the specified label, and then the return command would return to the previous label. Is there a simple way to do this and I’m just being plain stupid? I’m relatively new to TI Basic so I’m just sort of playing around so far.
Hey! Welcome to Cemetech!

For TI-Basic, the commands are WAY different. Maybe something like this.


Code:
ClrHome
Lbl AA
Repeat K=16
getKey->K
End
Goto BB

Lbl BB
Disp "you're here, press enter to go back"
Pause
Goto AA //maybe not what you want, but I think Return is for subprogs


Tell me if you wanted something different.
There is lots of information about this here.
Elijah wrote:
In some other BASIC languages I’ve used, there has been a way to jump from a label to another one and then return to the first label.

Example:

Code:

LABEL 0
IF BUTTON()==16 THEN GOSUB LABEL 1
GOTO LABEL 0

LABEL 1
PRINT “HELLO”
RETURN
END


The gosub command would go to the specified label, and then the return command would return to the previous label. Is there a simple way to do this and I’m just being plain stupid? I’m relatively new to TI Basic so I’m just sort of playing around so far.


TI Basic is pretty much the same, with some minor changes. A program in TI Basic would be:

Code:

Lbl 0
While 1
getKey->K
If K=16:Then
Goto 1
End
End
Lbl 1
Disp "Jumped to code
Pause

However, that's generally a bad practice because it creates a memory leak. Implementing the return command like in the sample code you gave is better. I use a subprogram to do this.

Code:

Lbl 0
While 1
getKey->K
If K=16:Then
prgmLBL1
End
End

PRGM:LBL1

Code:

Disp "Jumped to code
Pause
Return


Hope that helped a bit Smile
jcgter777 wrote:
Hey! Welcome to Cemetech!

For TI-Basic, the commands are WAY different. Maybe something like this.


Code:
ClrHome
Lbl AA
Repeat K=16
getKey->K
End
Goto BB

Lbl BB
Disp "you're here, press enter to go back"
Pause
Goto AA //maybe not what you want, but I think Return is for subprogs


Tell me if you wanted something different.


Yeah, I didn’t really know how to write a program example from a different language into a TI Basic code box.

I want to reuse some code without having to rewrite it for each label that uses it or use subprograms. Maybe an example would be having a little text rpg thing where each area is a different label. If I wanted to use a sword action, I would perhaps make a new label with the sword code. The label with the area would jump to the sword label and use Goto to return to the area code. But if each area is a different label, then how would I jump to the sword label and make it go back to my previous label? Can I set a variable to a label name and the use Goto (variable)?[/code]
What I basically want to do is jump to a label and then return to the previous one, but there are multiple labels that use that one label. Can I set a variable to a label name and then use goto (label name)? My loops usually consist of labels with infinite goto loops and I don’t want to use subprograms.

Here’s a link with the gosub command for the other language: http://petitcomputer.wikia.com/wiki/GOSUB_and_RETURN_(Command)
There is no easy way to do this simply because TI-BASIC doesn't directly offer this or related functionality in any way other than with external subprograms. However, if you were to actually read the link that was posted multiple times in this topic, it describes multiple ways to get around this without an external program.
jacobly wrote:
There is no easy way to do this simply because TI-BASIC doesn't directly offer this or related functionality in any way other than with external subprograms. However, if you were to actually read the link that was posted multiple times in this topic, it describes multiple ways to get around this without an external program.


I have opened the link and read the internal subprograms section. However I have a specific layout that I am already using in a program, and none of these methods accommodate it.

Sorry if I’m getting obnoxious. I guess I’ll just close the thread.
Nothing you've described can't be done (albeit verbosely) with techniques on that page.

Code:
GOTOSUB LABEL 1

Code:
For(A,0,1
If not(A
Goto 1
End


Code:
LABEL 1
PRINT "HELLO"
RETURN
END

Code:
While 0
Lbl 1
Disp "HELLO"
End
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement