TI 83/84
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Dev Hardware ForumsSOFTWARETI 83/84

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Hardware Forums Sponsor:
  Trader Rating: 0 · #1  
Old September 13th, 2009, 11:32 AM
YottaFlop YottaFlop is offline
n00b DevH'er
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 13 YottaFlop User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 49 m
Reputation Power: 0
Gravity

I tried to make a simple program in order to test gravity on a simple point. Here's the code.

Code:
ClrHome
ClrDraw
Horizontal -10
0->X
5->Y
Lbl 1
Pt-Off(X,Y,2)
Pt-On(X,Y,2)
If Y>-9
Then
Y-.5->Y
Goto 1


The idea is to have the point move down until the specified area, which it does, and delete all the previous points, which it fails to do. What's the problem? Thanks.

Reply With Quote
  Trader Rating: 0 · #2  
Old September 13th, 2009, 08:21 PM
MufinMcFlufin's Avatar
MufinMcFlufin MufinMcFlufin is offline
The Muffinator
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2008
Location: South Eastern USA
Posts: 208 MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 1 h 25 m 39 sec
Reputation Power: 95
Quote:
Originally Posted by YottaFlop
I tried to make a simple program in order to test gravity on a simple point. Here's the code.

Code:
ClrHome
ClrDraw
Horizontal -10
0->X
5->Y
Lbl 1
Pt-Off(X,Y,2)
Pt-On(X,Y,2)
If Y>-9
Then
Y-.5->Y
Goto 1


The idea is to have the point move down until the specified area, which it does, and delete all the previous points, which it fails to do. What's the problem? Thanks.

I looked at your program, and found it was because you have the point on and off backwards. Also, you should delete the Then statement, because it looks like if you let it go long enough, then you're going to fill up it's memory.
With If statements, you don't have to use Then if there's only one line you want it to do.
Also, If you use Then, then you have to use a End statement to signify, "Here's where I want it to stop doing things only if it meets the statement."
This is kind of where knowing other programming languages is helpful, but by far not necessary.
Here's an example from Java.
Code:
...some coding...
If(X>10)
{
 X=X-A;    ------Ignore this line, as this is basically store on TI BASIC, except backwards.
 A=2A;     ------This one too.
}
...and the rest of the program...

You see the opening and closing brackets?
The opening one says, "Do everything below here if the if statement is true" and is like Then on the calc. The closed one below it says, "OK, now whether or not that statement was true, continue the program below here as normal." and is like the End statement on the calc.
The reason why you would run out of memory if you let this code run long enough is because you have a goto statement before the (nonexistent) End statement. When it does a Then statement, the calculator tells itself, "ok, I got one more End statement to look for from here on out", but when there aren't anymore End statements, the calculator has too many to handle in it's RAM, so it overloads, and stops the program.
Avoid using goto statement's in between a Then and End statement, especially if it's in a part where the program will be going to a lot.
On the other hand, though it will only run through this program 20 times, so you don't really have to worry about it, but please don't make this sort of thing a habit. One minute you think you're program is doing great, next thing you know, have to re-write the entire thing to keep that from happening.
Ok, sorry for the lecture, but there's a lot that needs be said. If you want a program to loop through itself quickly, there's better ways than Lbl and Goto, as these will (generally speaking) slow down large programs significantly. There are better and faster ways to do it. The calculator has 3 (built in) types of loops you can use: For(, While, and Repeat. I say built in because you can also execute a program inside itself (called recursion) but that generally is not recommended.
For( is a loop that counts as it goes, with it's syntax (or parameters) as follows, with the thing in the brackets optional:
Code:
:For( Counting Variable, Starting Value, Ending Value [, Step Value])
:End

Like I said, it's a counting loop, so it needs 3 things. Some variable to use to count, a place to start, and a place to end. It also needs a value to count by, but if you leave that off, it will automatically count by ones. If you choose to try and better yourself in programming, then you will use For( all the time. I'm pretty good myself, and I think I use it more often than any other type of loop. If you wanted to display every number from 1 to 100, then you would probably use a for loop, like so:
Code:
For(A,1,100
Disp A
End

Look at it and you will be able to tell that it uses the Variable A, stores it as 1, then counts up by one, because I didn't specify to count by any other number, and keep counting up until 100, then it finishes.
If you wanted to do every even number, then this would be what you would want to do:
Code:
For(A,0,100,2
Disp A
End

This time, because I told it specifically to count by 2, it will display 0, then add 2, then display 2, and so on and so forth.
And the same goes for any other value you entered into the fourth parameter.
And that's about all you need to know for the For( loop.

While is simpler. What it basically does is go through the loop, WHILE the statement you tell it is true.
This is often used for the engine of a program. Keep letting the player control the character, WHILE he's alive.
Keep the player working on the puzzle WHILE he hasn't beaten it.
(From personal experience,) Have the player keep working on the Sudoku puzzle while he doesn't have 81 correct numbers.
And so on.
Usually one would do this with a statement like X>0, or A=X, and so on, but you can change it if you want into an infinite loop.
Notice that if you enter in the homescreen X=X, it displays 1. And if you display X=X-1, it displays 0. This is because the way the calculator displays true or false is 1 or 0, respectively. So essentially if you told the program While true, then it would infinitely loop through it right?
While 1 yields an infinite loop, as 1 never stops being 1, and thus the loop is never false, and always will loop.
Same works for If statements, but if you tell it If 1, then you may as well not have the If statement in the first place.
And that's about all there is to a While statement, except that it's good to know that it checks to see if it's true or false at the beginning of the loop. So you can replace this:
Code:
...some code...
If X=1
Then
While X=1
...some coding here...
End
End
...rest of code...

with this:
Code:
...some code...
While X=1
...some coding here...
End
...rest of code...

This gets to be pretty helpful, but sometimes you will need it to loop through at least once. That's where the Repeat command comes in (please bear with me, this is the last part of this lecture of epic proportions, even for my own standards, and now that you know of the other two loops, this will be easy)

Repeat, is basically the opposite of While.
Repeat will, simply put, Repeat the inside of it, UNTIL it's true.
This also is used many times for engines, but is also used for getKey, which if you don't already know about, then tough luck, my hands are getting tired.
Also another big difference between While and Repeat is that Repeat checks at the end of the loop, so it will always go through the loop at least once. So if you were making a card game and needed all the cards to be different, then you would tell it to randomly choose a card, and if that card were to equal the value of any other card, then choose another card.
And that's pretty much all I can think of for Repeat.

Like I said before, technically you can execute the program inside itself so it repeats itself, but you can also run out of memory if you do that, and such a method of looping (called recursion) is often fragile, and could "break down" catastrophically if done incorrectly (Error after Error, shouldn't sound like much fun if you're a programmer).

And that's about it.
Use those loops wisely and be sure you're using the right one for the situation. Never forget you're End commands, because those should be seen as often as For('s, While's, and Repeat's combined.
And if you have any other questions, I'll try and give them shorter explanations.
Oh, and for the program, I can post my own bouncing programs that use actual physics equations to accurately replicate reality (the ball accelerates to the ground instead of moving at a constant speed, and loses inertia as it impacts the ground)
They're pretty cool to watch, especially when bored in school, and work pretty well, but one of the is meant for the 84+, and will go very slow on the 83...
__________________
日本のクールだ
Ich liebe Deutsch!

TI BASIC Tutor

Last edited by MufinMcFlufin : September 13th, 2009 at 09:43 PM.

Reply With Quote
  Trader Rating: 0 · #3  
Old September 14th, 2009, 06:34 PM
YottaFlop YottaFlop is offline
n00b DevH'er
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 13 YottaFlop User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 49 m
Reputation Power: 0
Wow, thanks!

You should write a book.

Reply With Quote
  Trader Rating: 0 · #4  
Old September 18th, 2009, 09:16 AM
MufinMcFlufin's Avatar
MufinMcFlufin MufinMcFlufin is offline
The Muffinator
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2008
Location: South Eastern USA
Posts: 208 MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 1 h 25 m 39 sec
Reputation Power: 95
Quote:
Originally Posted by YottaFlop
Wow, thanks!

You should write a book.

lol, thanks, but no thanks
I'm not much of a novelist
Anyways, do you want me to post that bouncing program I was telling you about?

Reply With Quote
  Trader Rating: 0 · #5  
Old November 18th, 2009, 04:39 PM
Regular Joe Regular Joe is offline
n00b DevH'er
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 17 Regular Joe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 30 sec
Reputation Power: 0
I know i am not involved in this thread, but would really appreciate it if you would post that bouncing program.

Reply With Quote
  Trader Rating: 0 · #6  
Old November 22nd, 2009, 09:22 AM
MufinMcFlufin's Avatar
MufinMcFlufin MufinMcFlufin is offline
The Muffinator
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2008
Location: South Eastern USA
Posts: 208 MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level)MufinMcFlufin User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 1 h 25 m 39 sec
Reputation Power: 95
Quote:
Originally Posted by Regular Joe
I know i am not involved in this thread, but would really appreciate it if you would post that bouncing program.

Well my calculator's batteries are recharging at the moment, and I won't be able to give you the official one at the moment, but here's a quick one. I had like 6 versions of the program, (I can't remember them all at the moment though...) and I'll post them once my calc is charged up again.
Code:
ClrDraw
Vertical Xmin
Vertical Xmax
Horizontal Ymin
Horizontal Ymax
{1,randInt(1,93),0,1-2randInt(0,1),0,0
While 1
{Ans(1),Ans(2),Ans(3),Ans(4),Ans(1),Ans(2
If sum(Ans(2)+Ans(4)={1,93
Then
{Ans(1),Ans(2),Ans(3),-Ans(4),Ans(5),Ans(6
End
If Ans(1)+Ans(3)≥62
Then
{Ans(1),Ans(2),-Ans(3),Ans(4),Ans(5),Ans(6
End
If Ans(1)=63
Then
{1,Ans(2),0,Ans(4),Ans(5),Ans(6
End
{Ans(1)+Ans(3)+1,Ans(2)+Ans(4),Ans(3)+1,Ans(4),Ans  (5),Ans(6
Pxl-On(Ans(1),Ans(2
Pxl-Off(Ans(5),Ans(6
End

This one's pretty cool because it actually doesn't involve any variables at all (just Ans)! The only problem you'd really have is with using this program when there's a function on the screen, and has been optimized for speed so it can be reduced in size (memory wise). Anywho, I haven't tested it yet, so there may be a glitch or two in there. Give me some time so I can get a new TI Emulator (I had to reformat my computer so I now need a new one) and I'll test it out and debug it if necessary.

Reply With Quote
Reply

Viewing: Dev Hardware ForumsSOFTWARETI 83/84 > Gravity


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
     
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 11 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek