Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: joao9856 on January 24, 2013, 09:43:31 am

Title: Need help
Post by: joao9856 on January 24, 2013, 09:43:31 am
Is it possible to call a program from inside another program?
Title: Re: Need help
Post by: Scipi on January 24, 2013, 09:51:58 am
It is in TI Basic

Under the prgm menu, go to the exec tab and directly enter the program you want to call on it's own line in the editor.
Title: Re: Need help
Post by: joao9856 on January 24, 2013, 10:08:03 am
i can't find that. Also important info i'm using Ti-Nspire
Title: Re: Need help
Post by: ElementCoder on January 24, 2013, 10:10:38 am
Well than you can't find that indeed :P Homer gave instructions for the TI84 series (which is assumed if you say "TI BASIC"). For Nspire, you just call a program by typing its name. example:
Code: [Select]
Define example()=
Prgm
anotherprogram()
EndPrgm
Title: Re: Need help
Post by: Scipi on January 24, 2013, 10:34:19 am
i can't find that. Also important info i'm using Ti-Nspire

Whoops, my bad. I assumed the 83/84 due to the forum category :P

(Now that I think about it, do we have a separate forum for Nspire-Basic?)

ElementCoder gave the method for the Nspire. However, if I remember correctly subroutines called in a program must be defined elsewhere in the same document. I think there's a way to make it so you'll only need to define a program once and not everytime you use a new document, but it's been a while since I've done anything with the Nspire. <.<
Title: Re: Need help
Post by: joao9856 on January 24, 2013, 10:34:53 am
i called a program in an if statement and it does not save the variables

Code: [Select]
define example()
requeststr"a b c",choose,0
if choose="b" then
bcode()
text"its b"

its something like that what i've created
Title: Re: Need help
Post by: Scipi on January 24, 2013, 10:39:30 am
Choose may be a local variable in the parent program, and thus bcode() doesn't know about it.

You could have choose as a global variable or pass in an argument to bcode()

Code: [Select]
define example()
requeststr"a b c",choose,0
if choose="b" then
bcode(choose)
text"its b"

Like so.

Edit: bcode() would look like

Code: [Select]
define bcode(choose)
Title: Re: Need help
Post by: joao9856 on January 24, 2013, 10:49:22 am
got it i didn't need to change anything but thanks.
next time i should remember to save all programs. :crazy:
What happened was that i was building a program and saved it so i could see its working, but i forgot to save the "bcode program", so i was trying to runa program that was not there.
Title: Re: Need help
Post by: ElementCoder on January 24, 2013, 10:53:01 am
...I think there's a way to make it so you'll only need to define a program once and not everytime you use a new document...
There is, you'd have to make your program LibPriv or LibPub. LibPub will make it show up in the catalog, LibPriv means it won't. This can be set in the program editor by going to menu>1: Actions>7: Change Library Acces. You'd then access it by calling <libraryname>\function()

Yeah running a program that isn't there won't do much :P though that should have given you an error "Function not defined" (or you must mean you gave it no body).
Title: Re: Need help
Post by: joao9856 on January 24, 2013, 10:55:45 am
probably only saved it while it was clean
Title: Re: Need help
Post by: ElementCoder on January 24, 2013, 10:57:30 am
I have just decided to pick up my "book-that-never-came-further-than-title-page" about Nspire BASIC, I should have a chapter or two done by the end of the week, though that probably won't be of help for you, Ch.1 will be about the editor and it's functionality and Ch.2 will be the hello world :)
Title: Re: Need help
Post by: joao9856 on January 24, 2013, 11:00:14 am
I think i wont be learning much, but i never know specialy because i only code in ti-nspire with simple tasks, that is before my current project.(trying a menu only rpg with level system :hyper:)
Title: Re: Need help
Post by: ElementCoder on January 24, 2013, 11:02:25 am
If you want to make an RPG you should most definitely look at TI RPG and TI RPG 2 both by Superbany, especially the latter is extremely well made.
Title: Re: Need help
Post by: joao9856 on January 24, 2013, 11:04:01 am
thanks for the help!
Title: Re: Need help
Post by: joao9856 on January 25, 2013, 09:56:08 am
New question, is there anyway of puting a variable inside a requeststr like this:
Code: [Select]
request "I have x peanuts and you?",peanuts,0
Edit:another Question

How can i from a number like 9.57 turn into 9?
if you didn't understand please say it.
Title: Re: Need help
Post by: ElementCoder on January 25, 2013, 10:03:23 am
You have to use the string concatenation operator:
Code: [Select]
Text "I have "&string(x)&" peanuts"
If x is a string you can leave out the 'string()' command. If x is a non string value, you have to stringify it first using 'string(argument)'.
Title: Re: Need help
Post by: joao9856 on January 25, 2013, 11:17:26 am
i edited last post(alot), and i don't think it works with request.
EDIT: Made it thanks
Title: Re: Need help
Post by: ElementCoder on January 25, 2013, 03:03:37 pm
With request is the same way :) And for new questions you should just post again. That way we can see you have a new question, plus now it looks like my answer comes out of nowhere. Don't use edit to delete you entire previous question, just ask again :)
Title: Re: Need help
Post by: alex99 on May 06, 2013, 01:33:45 pm
With request is the same way :) And for new questions you should just post again. That way we can see you have a new question, plus now it looks like my answer comes out of nowhere. Don't use edit to delete you entire previous question, just ask again :)
oooookkkkkk