[TI BASIC] Number of IF statements allowed?

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Clordio
New Member
Posts: 14
Joined: Thu 22 Feb, 2007 6:28 am

[TI BASIC] Number of IF statements allowed?

Post by Clordio »

Newb alert! Newb alert! Lol, ok so I am using tutes and such to teach my self basic on the TI-83. After each lesson, I try to use the new functions I have learned in all sorts of ways to help gain better understanding. So I just learned If Then statements and I was wondering if there is a number of allowed If's? My code goes like this.

Code: Select all

ClrHome
4->C
4->B
Lbl D
prompt A
If A=4
B-1->B
Goto E
End
If A=6
B+1->B
Goto E
End
If A=2
C-1->C
Goto E
End
If A=8
C+1->C
Goto E
End
Lbl E
ClrHome
Output(C,B,"?"
Goto D
Basically I'm just moving the question mark around the screen. Problem is, it will only move left and right... I've switched which commands come first and the first 2 If's work, but the last two don't. Help please.
:cry:
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

"If" does not go with "End"
"If" "Then" goes with "End"

"If" is just used on its own and it will skip the NEXT like when FALSE, "If" "Then" will skip everything until the next "End" when FALSE. If the condition is true then they do nothing except take time. (TRUE being 1 or greater)

Also, those "End"s you have will never be executed since you "Goto" before the parser gets to them. "Goto"s are relatively slow and unreachable code is not very useful.


So, to fix your code, add a "Then" after every "If" ("Then" can be found right between "If" and "Else")

Or better yet:

Code: Select all

1->A
1->B
repeat 0
repeat Ans
getKey
End
Ans->K
Output(A,B,"   %that is 1 space, and this is a comment
B+(K=26)(B<16)-(K=24)(B>1)->B
A+(K=34)(A<8)-(K=25)(A>1)->A
Output(A,B,"?
End
Untested but should work ('work' being defined as "moves a question mark around the screen using the arrow keys")

Lesson learned: conditionals build into functions are faster than If/Then statements.


PS: the number of IF statements allowed is unlimited except by the size of the RAM.
Last edited by King Harold on Thu 22 Feb, 2007 2:13 pm, edited 1 time in total.
Clordio
New Member
Posts: 14
Joined: Thu 22 Feb, 2007 6:28 am

Post by Clordio »

Awesome, thank you King Harold. I haven't learned getkey or repeat yet, so I don't understand that code you used just yet. But I'm definitely happy to have my little ram eating noobasaurus code running. :D
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

I edited my example program so that it works (changed zero to 1 at the beginning)

I'm glad you got it working


Repeat conditional
code
End

works a bit like:

label X
code
If not(conditional
goto X

But repeat stores the adres to which it should loop back, unlike goto, this is faster but if you escape the loop (with goto) then Repeat will fill the RAM with pointers and eventually the calculator will slow down and give a ERR:MEMORY, so be careful to make the conditional so that you will never have to escape a Repeat loop with "Goto".
Clordio
New Member
Posts: 14
Joined: Thu 22 Feb, 2007 6:28 am

Post by Clordio »

Awesome, thanks for the advice. I remember coming to Maxcoderz.com YEARS ago when you guys had an actual front page. I always wanted to be a part of this coding scene and it's great to get started. After I master TI Basic, I hope to learn C or C++, basically something to get me ready for ASM.

I really like Basic though because you can do it right on the calculator. Is there some sort of program that allows you to write and compile ASM on the calculator itself?
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Yes there is, there are many on-calc compilers (I hope I can rewrite my own failed one some day..) like "TASM on calc" and "Chasm" and many others. Or you could write native code in a program which starts with AsmPrgm, but that's hard (I do that in math class, I have a program which is a list with all commands and their code, I look up the command and type the code in the assembly program) you can squish it with AsmComp(sourceProgram,nameOfCompiledProgram
don't forget the prgm tokens in front of the names

There is still a frontpage, but I liked to old one better I think..

Also, I would say calculator ASM is easier than C++, and if you want to learn a C-type language I think it might be best to learn C# which is a lot easier than C++ and just as powerful.
Clordio
New Member
Posts: 14
Joined: Thu 22 Feb, 2007 6:28 am

Post by Clordio »

The only reason I wanted to learn C was so I could be ready for ASM on the calc. What programming language should I learn before ASM? C#?
threefingeredguy
Calc King
Posts: 2195
Joined: Sun 27 Mar, 2005 4:06 am
Location: sleeping
Contact:

Post by threefingeredguy »

No. No. NO. C# is like the opposite of ASM. Why not just learn ASM?
Image
Clordio
New Member
Posts: 14
Joined: Thu 22 Feb, 2007 6:28 am

Post by Clordio »

Well I keep hearing that you should learn another language first. I want to just start with ASM, is it possible? I'm on a mac, so I'm wondering if there are any restrictions for that.
threefingeredguy
Calc King
Posts: 2195
Joined: Sun 27 Mar, 2005 4:06 am
Location: sleeping
Contact:

Post by threefingeredguy »

Yes, there are no tools for developing ASM on a mac. If you have an intel-based one, it's possible to convert Spasm. Also, when there is support for Visual C++ apps (coming in the future, I hear) you should be able to run Brass.

There's also a web-based assembler somewhere that someone could provide a link for, but I don't think you can make them into 8xps with that.

Also, no one post a link to that assembler from ticalc.org for mac. It does NOT work. I've tested it on 8.1, 8.2, 9.2, and all versions of OS X. It does NOT work.
Image
Clordio
New Member
Posts: 14
Joined: Thu 22 Feb, 2007 6:28 am

Post by Clordio »

Ok. Maybe some of the ASM developing tools will work on a pc emulator? I'd really like to get into ASM after I learn Basic, or maybe I should try to learn how Xlib works? So many choices lol, but I'm excited.

Quick question are physics at all possible in Basic? Not the science but like platformer physics. My first game I want to be a platformer.
threefingeredguy
Calc King
Posts: 2195
Joined: Sun 27 Mar, 2005 4:06 am
Location: sleeping
Contact:

Post by threefingeredguy »

Yes, but it's fairly slow. About the fastest you can get will be something like CDI's Metroid. You can see a couple examples of that in the Staff/Featured Projects Forum.
Image
Clordio
New Member
Posts: 14
Joined: Thu 22 Feb, 2007 6:28 am

Post by Clordio »

This has been a great welcoming and I already feel at home in this forum. Thanks so much everybody, and I hope to post my first game in the next month here. Won't be anything flashy lol.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

threefingeredguy wrote:Also, when there is support for Visual C++ apps (coming in the future, I hear) you should be able to run Brass.
For the record, I'm no masochist. Brass is written in C#, not C++, and so will run under MacOS via Mono.

However, automatic app signing relies on COM interop with TI's Wappsign, so won't work.
User avatar
CDI
Maxcoderz Staff
Posts: 321
Joined: Tue 24 May, 2005 7:25 pm
Location: If I find out, you'll be first to know.
Contact:

Post by CDI »

Physics are fast and fun, Axcho proved this with his intuitave N-Game engine, and if you work around it, you can apply it to a platformer easily. The hardest things are friction and gravity. For most of the things I do, I cheat and make the terminal velocity of the player quite low. Friction is a good effect on something like ice, for instance you can set normal blocks to have a friction on 100%, meaning you can move one over and not keep sliding out of control, while your ice may have a friction of 50%, so you press left and your character goes left, and then left again!

threefingeredguy, if you are referring to Metroid 1, that was a failure at coding and I still need to update it with the Metroid Pure engine(s). Metroid Infinity is at least 3x faster in some places, and up to 4 or 5x faster so HA ;)
ImageImage
Post Reply