If I'm making a game in TI-BASIC which takes user input and updates the position of an onscreen cursor, two options which come to mind are to store the position as a list of length 2 or as a single variable. For instance, my minesweeper game stores the position as {Row, Column} in a list (LCRSR) and retrieves the current row or column as needed (LCRSR(1) or LCRSR(2)).

However, I was thinking it might be faster to store the info for both values in a single variable such that if the cursor position is stored in variable A, int(A) = Row and 100fPart(A) = Column. (e.g. A=1.01 when Row=1 and Column=1).

Does anyone know which option is faster when the program is running? I would assume using a variable is probably faster since it takes up less space in RAM, but I kind of prefer the list approach because it feels less confusing to actually write.
Without doing any testing, I believe that using the list would be significantly faster than using a single variable. When you store a coordinate using the integer and fractional parts of a single real variable, more operations are required to get and set the individual components.

For example, setting the column (A is the composite coordinate, and C is the new column):

Code:
iPart(A)+C/100->A
vs.
Code:
C->LCRSR(2


It would be even more efficient to use two separate real variables to store the row and column, since you would only need a single character to reference the row or column, versus 4-7 for the list.
  
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 GMT - 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