Help with my coding, please

  • Topic Archived
  1. Boards
  2. Petit Computer
  3. Help with my coding, please
3 years ago#1
I'm trying my hand at a simple program to print a Shakespearean Insult.

I thought I'd use the read and data command, but I can't seem to get it to work. The code is listed below.

I keep getting the error Syntax Error (6, READ) (Insufficient DATA available for a READ)

I have it set up so that each DATA statement holds one word from column1, column2, column3
There are 50 DATA statements, so I have a FOR-NEXT loop to load the data, but it never gets that far.

Does this mean I have to put each word on a separate DATA line? I thought they could be separated by commas, and still work.

I haven't touched BASIC in years, so any help would be appreciated

Regards,

Brian


PRINT "Shakespearean Insult Generator"
PRINT
REM Read the data for the three columns
DIM C1$(50):DIM C2$(50):DIM C3$(50)
FOR I=1 TO 50
READ C1$(I)
READ C2$(I)
READ C3$(I)
NEXT I
REM Choose three random numbers
O=(RND(50)+1)
T=(RND(50)+1)
R=(RND(50)+1)
REM Print Insult
PRINT "Thou "+C1$(O)+" "+C2$(T)+" "+C3$(R)
END
DATA "artless","base-court","apple-john"
DATA "bawdy","bat-fowling","baggage"
DATA "beslubbering","beef-witted","barnacle"
etc.
---
3DS FC: 0989-1868-2072
Lookin' for friends
3 years ago#2
I'm not sure, but you probably need to put a label in front of the data like @INSULTS and then before accessing it use RESTORE @INSULTS
3 years ago#3
The main thing to note is that all arrays in the program are zero-based. That is, for an array declared DIM C1$(50), the first element is C1$(0), the second element is C$(1), and so on, to the 50th element, which is C1$(49). Thus, your first IF statement should be:

FOR I=0 TO 50

, which will iterate 0, 1, 2...49.

The second thing to change would be those three RND() statements, which shouldn't have 1 added to them, because of the aforementioned zero-based index thing. Leaving them as is is fine, since RND(50) will select a number from 0-49, which is right in the range of the arrays you are declaring.

I don't think you need to RESTORE to the start of the DATA though, since READ by default will start reading from the first DATA in your program.
---
Activity is overrated.
LOLLANDMASTER - SBAllen, 2/2/08
3 years ago#4
No, the FOR statement should go from 0 to 49, not 50.
3 years ago#5
UncleSporky posted...
No, the FOR statement should go from 0 to 49, not 50.

Ah dang, you're right. Please disregard what I said on the upper limit, seems I didn't understand that part very good either.
---
Activity is overrated.
LOLLANDMASTER - SBAllen, 2/2/08
3 years ago#6
Thanks to everyone for your advice. It worked! I finally got my first program working in Petit Computer!

I'll upload the QR codes this weekend if anyone is interested. I'll keep going with it to try and add new capabilities one at a time to try and teach myself more of the BASIC language.

Regards,

Brian
---
3DS FC: 0989-1868-2072
Lookin' for friends
3 years ago#7
I'm not too familiar with DATA structure handling in basic, I'd be interested!
3 years ago#8
For anyone who wants it, here's a link to the qr codes:

http://www.flickr.com/photos/brianka_99/sets/72157630906042760/

I hope they work, I just signed up with flikr to start sharing this stuff.

Ignore the code for the buttons, because I'm still trying to figure that out. All I can do at the moment is create another insult by pressing A.

If anyone can suggest better code to use the buttons, I'd appreciate it.

Regards,

Brian
---
3DS FC: 0989-1868-2072
Lookin' for friends
3 years ago#9
Thanks for sharing! I downloaded and worked as expected. :) I actually learned how to use the data statements just by following your code.
---
3DS Friend Code: 1676-4542-1252 (Upokupo) Please, PM with your code if you add me. Thanks ^^
3 years ago#10
If you take the REM part out of line 22 and add another = it should work.
If BTRIG()==64 THEN GOTO @END.
  1. Boards
  2. Petit Computer
  3. Help with my coding, please

Report Message

Terms of Use Violations:

Etiquette Issues:

Notes (optional; required for "Other"):
Add user to Ignore List after reporting

Topic Sticky

You are not allowed to request a sticky.

  • Topic Archived