I recently created a program that simply bounces a line around the screen, deflecting off the edges (much a screen saver bounces around a monitor). I wanted to give it a little more interest, so instead of having it start at (0,0) each time, it would start at a random point on the screen. Below is the code I currently have:


Code:

:ClrDraw
:AxesOff
:randInt(1,92)→X
:randInt(1,62)→Y
:1→A
:1→B
:While 1
:Pxl-On(Y,X)
:A+X→X
:B+Y→Y
:If X≥93
:-1→A
:If X=1
:1→A
:If Y≥62
:-1→B
:If Y=1
:1→B
:End


Now something entirely inexplicable (to me) is happening when I run this code. After one iteration of the loop, which turns on a pixel at the randomized location, say (45,70) for this example, the value of B is being store to Y, moving the whole operation up to (1,70) in one loop. I know that it is B being stored to Y because I have tried changing the value of B to -1, which obviously returns with a Domain Error when the calculator tries to graph a pixel at (-1,70).

Why on Earth is this happening?! There is absolutely nothing in the code that would allow B to store to Y without adding the initial value of Y first. I'm completely baffled by this, and it's frustrating me beyond belief. Please help me out here.

Thanks,
-- PinSeventy
Without analyzing the code i can tell you that there are often problems with using the X & Y TIOS variables.

Have you tried substituting X/Y with different variables?
tr1p1ea wrote:
Without analyzing the code i can tell you that there are often problems with using the X & Y TIOS variables.

Have you tried substituting X/Y with different variables?


I replaced them with C and D and it worked perfectly, thank you very much sir.
Yeah, the X and Y variables are used internally for graphing, if I recall correctly. Try to avoid using them.
  
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