Return to Level1Techs.com

Playing on a commodore 64, need help

Ok, I’m trying to write this simple text game on a commodore 64. (trying to learn basic first) And i for the life of me cannot understand why it’s having issues with my code. it keeps saying:

?UNDEF’D STATEMENT ERROR IN 170

But I cannot for the life of me understand what it means. Here’s my code

10 REM - THIS NUMBER GUESSING GAME IS BASED ON GUESS AND HI-LO

20 REM - FROM DAVID H. AHL’S BOOK BASIC COMPUTER GAMES.

30 PRINT “=======”

40 PRINT " ZERO!"

50 PRINT “=======”:PRINT

60 PRINT “I CHOOSE A NUMBER BETWEEN 1 AND 100.”:PRINT

70 PRINT “YOU MUST ZERO IN ON IT IN 7 GUESSES.”:PRINT

80 PRINT “I TELL YOU TO GUESS HIGHER, OR LOWER.”:PRINT

90 INPUT “PRESS ENTER TO START. READY”; START$

100 NUM = INT(100*RND(1))

110 PRINT:PRINT “====================”:PRINT

120 PRINT "I HAVE CHOSEN A NUMBER ":PRINT:NUM

130 FOR COUNT = 1 TO 7

140 PRINT "GUESS ";COUNT;

150 INPUT ": "; GUESS$

160 GUESS = VAL(GUESS$)

170 IF GUESS = NUM GOTO 250

180 IF GUESS > NUM THEN PRINT “GUESS LOWER”

190 IF GUESS < NUM THEN PRINT “GUESS HIGHER”

200 PRINT

210 NEXT COUNT

220 PRINT:PRINT “YOU’VE USED ALL OF YOUR GUESSES.”

230 PRINT “THE NUMBER WAS”;NUM

240 GOTO 270

250 PRINT "YOU GOT IT IN ";COUNT;

260 PRINT " GUESSES."

270 PRINT

280 INPUT "PLAY AGAIN? (Y/N) "; A$

290 IF A$ = “Y” THEN GOTO 100

300 END

Can anyone help me understand where I’m wrong?

Maybe with a then?

170 IF GUESS = NUM THEN GOTO 250

nope just tried that, still not working

This one works:

10 REM - THIS NUMBER GUESSING GAME IS BASED ON GUESS AND HI-LO
20 REM - FROM DAVID H. AHL’S BOOK BASIC COMPUTER GAMES.
30 PRINT "======="
40 PRINT " ZERO!"
50 PRINT "=======":PRINT
60 PRINT "I CHOOSE A NUMBER BETWEEN 1 AND 100.":PRINT
70 PRINT "YOU MUST ZERO IN ON IT IN 7 GUESSES.":PRINT
80 PRINT "I TELL YOU TO GUESS HIGHER, OR LOWER.":PRINT
90 INPUT "PRESS ENTER TO START. READY"; START$
100 NUM = INT(RND(1)*100)
110 PRINT:PRINT "====================":PRINT
120 PRINT "I HAVE CHOSEN A NUMBER ":PRINT
130 FOR COUNT = 1 TO 7
140 PRINT "GUESS ";COUNT;
150 INPUT ": "; GUESS$
160 GUESS = VAL(GUESS$)
170 IF GUESS = NUM GOTO 250
180 IF GUESS > NUM THEN PRINT "GUESS LOWER"
190 IF GUESS < NUM THEN PRINT "GUESS HIGHER"
200 PRINT
210 NEXT COUNT
220 PRINT:PRINT "YOU’VE USED ALL OF YOUR GUESSES."
230 PRINT "THE NUMBER WAS";NUM
240 GOTO 270
250 PRINT "YOU GOT IT IN ";COUNT;
260 PRINT " GUESSES."
270 PRINT
280 INPUT "PLAY AGAIN? (Y/N) "; A$
290 IF A$ = "Y" THEN GOTO 100
300 END

what did you change? sorry, i’ve been staring at this all day, i can’t see the differences. my eyes are so boggy

Mainly the to ". Something must have reformatted those. (That’s why I just edited the last post again btw. Happened here as well) Also I removed the NUM from line 120. No point in playing otherwise, right?

Huh, the num from that line isn’t supposed to print. At least it doesn’t on my end.

Ah, right. I was wondering what that one did and tried 120 PRINT "I HAVE CHOSEN A NUMBER ":PRINT NUM.
That worked but was showing the number of course so …

yeah, you forgot the : before num I think

That was throwing the error for me.

really? huh. I’ll reset my machine, and see if yours fixes all my problems

Here goes another 15 minutes of typing

BTW: If you’r running VirtualC64, you can totally cheat and copypaste. :stuck_out_tongue:

Sadly, I am not using an empulator. I’m using an actual C64. I found it in a dumpster in the city I live in. The only reason it was thrown out, was it wouldn’t boot up. Come to find out, the power button came unsoldered. Works perfectly fine. Not a scratch on it.

And this forces me to actually type everything in, and LEARN what the commands do lol.

1 Like

Did that when I was 10 or so, don’t need that anymore in my life.
Fuck you, Datasette! :rofl:

Did get a 1541II eventually. And from then on it was just pirated games anyway. xD

I’m trying slowly to get back into coding. Figured i’d get back to basics cause I forgot everything I knew. Once I get down Basic on c64 I plan to just keep going up the line till I know something worth possibly getting a job for. I’m 38 and haven’t done much with my life, I wanna get back to where I was. And maybe do something with my life.

1 Like