Sunday, July 21, 2013

Tutorial #6 - Data Tables

A very useful feature of Petit Computers BASIC is the DATA command. If you are programming a game this will allow you to set up a table filled with strings and integers to your hearts content. For example instead of manually typing IF cases for every line of text in a game, you can just store it in a data table and have your code READ what string needs to be printed and be done with it. I am going to keep this tutorial simple, but feel free to ask any questions you may have.


  1. ACLS:CLEAR:CLS 'Clear our setup

  2. RESTORE @MSGDATA 'This will load the data after @MSGDATA
  3. READ MSGCOUNT 'This will read the first variable stored in DATA, and that is our message count (3)
  4. FOR LOOP = 1 TO MSGCOUNT ' Loop through our data table
  5.  READ MSGX, MSGY ' This will read the X and Y locations of where our message should be printed into the variables MSGX and MSGY
  6.  READ MESSAGE$ ' Read the message string
  7.  LOCATE MSGX, MSGY 'Set our cursor to the stored X/Y location
  8.  PRINT MESSAGE$ ' Print off our message
  9. NEXT LOOP
  10. END

  11. @MSGDATA 'This is the label for our data table
  12. DATA 3 'This will store the #3, our message count
  13. DATA 0,0,"Hello" 'This will store the x, y, and string to print
  14. DATA 1,1,"How are you?"
  15. DATA 4,3,"Goodbye"

QR Code for this Tutorial

Homework

Topic 17 - Declarations and Assignment Commands
  • CLEAR
Topic 21 - Read
  • READ
  • DATA
  • RESTORE

No comments:

Post a Comment