Help with my coding, please

#1briankaPosted 8/1/2012 4:14:22 PM
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
#2someguy28898Posted 8/1/2012 4:24:54 PM
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
#3CastformREDPosted 8/1/2012 7:18:01 PM
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
#4UncleSporkyPosted 8/1/2012 8:48:40 PM
No, the FOR statement should go from 0 to 49, not 50.
#5CastformREDPosted 8/1/2012 9:43:14 PM
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
#6brianka(Topic Creator)Posted 8/3/2012 7:01:44 PM
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
#7NyyarkPosted 8/4/2012 9:33:15 AM
I'm not too familiar with DATA structure handling in basic, I'd be interested!
#8brianka(Topic Creator)Posted 8/4/2012 6:46:37 PM
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
#9UpochapoPosted 8/8/2012 5:14:23 AM
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 ^^
#10Fidgit80Posted 8/8/2012 9:24:22 AM
If you take the REM part out of line 22 and add another = it should work.
If BTRIG()==64 THEN GOTO @END.