unexpected
unexpected
hi following tutorials and trying something:
CLS
20 PRINT "TESTING"
21 K = INKEY$
22 IF K = "" THEN GOTO 21
23 IF K = "Y" THEN GOTO 25
24 IF K < > "N" THEN GOTO 26
25 PRINT "YES"
26 PRINT "NO"
ENDIF
but syntax error, unexpected K, expecting end of file. What can I do to fix??
CLS
20 PRINT "TESTING"
21 K = INKEY$
22 IF K = "" THEN GOTO 21
23 IF K = "Y" THEN GOTO 25
24 IF K < > "N" THEN GOTO 26
25 PRINT "YES"
26 PRINT "NO"
ENDIF
but syntax error, unexpected K, expecting end of file. What can I do to fix??
-
- Site Admin
- Posts: 207
- Joined: Fri Oct 06, 2023 8:25 pm
Re: unexpected
Hi zartan917, and welcome!
Note that this code will print YES and NO if the Y key is pressed.
I don't know if that's what you wanted to achieve.

In ugBASIC, variables must start with a lowercase letter. Variables whose names start with an uppercase letter cannot be used. Also, if you want to use IF...ENDIF on multiple lines, you must separate the commands with a return or a colon. So the code you wrote would look like this:
Code: Select all
CLS
20 PRINT "TESTING"
21 k = INKEY$
22 IF k = "" THEN GOTO 21
23 IF k = "Y" THEN GOTO 25
24 IF k <> "N" THEN GOTO 26
25 PRINT "YES"
26 PRINT "NO"
I don't know if that's what you wanted to achieve.

Re: unexpected
hi thank you. I pasted code now getting unexected OP_GT whatever that is. I didnt see where to add colons? after the thens?
-
- Site Admin
- Posts: 207
- Joined: Fri Oct 06, 2023 8:25 pm
Re: unexpected
Hi zartan917!
This could be the same example (on multiple lines):
Sorry, my mistake! Or rather, a copy and paste error. Actually, you should write <> to indicate different, and not < > (i.e. with a space in between). The OP_GT keyword stands for Greater Than OPerator, i.e. the > symbol. In fact, the parser cannot understand that the > symbol is part of a <> and, therefore, treats it as a syntax error. I fixed the source code.
This could be an example (on a single line):
Code: Select all
IF cond THEN: ... :ELSE: ... :ENDIF
Code: Select all
IF cond THEN
...
ELSE
...
ENDIF
Re: unexpected
hi that works thanks. To build upon it, im trying to have different pictures/text show up on different keypresses. so far no errors but it seems to just jump to the 2nd picture (line 29).. is there a "wait" function i need first? Do i have to keep declaring where to put the pictures (like on line 30?) ...
1 BITMAP ENABLE (16)
2 CLS
3 bgg := LOAD IMAGE("testp.png")
4 PUT IMAGE bgg AT 0,0
5 GOTO 20
20 PRINT "TESTING"
21 k = INKEY$
22 IF k = "" THEN GOTO 21
23 IF k = "Y" THEN GOTO 25
24 IF k <> "N" THEN GOTO 27
25 PRINT "YES"
26 GOTO 20
27 CLS
28 PRINT "OK"
29 bgg := LOAD IMAGE("loveu3p.png")
30 PUT IMAGE bgg AT 0,0
1 BITMAP ENABLE (16)
2 CLS
3 bgg := LOAD IMAGE("testp.png")
4 PUT IMAGE bgg AT 0,0
5 GOTO 20
20 PRINT "TESTING"
21 k = INKEY$
22 IF k = "" THEN GOTO 21
23 IF k = "Y" THEN GOTO 25
24 IF k <> "N" THEN GOTO 27
25 PRINT "YES"
26 GOTO 20
27 CLS
28 PRINT "OK"
29 bgg := LOAD IMAGE("loveu3p.png")
30 PUT IMAGE bgg AT 0,0
Re: unexpected
Keep both load IMAGES at the start of the code where the first one is.
Their variable names must be different, so "bgg" for the first image and maybe "bg2" for the second.
bgg := LOAD IMAGE("testp.png")
bg2 := LOAD IMAGE("loveu2p.png")
Then you PUT IMAGE bgg AT 0,0 for the first and PUT IMAGE bg2 AT 0,0 for the second.
You can add a WAIT KEY command in-between them so it only advances when any key is pressed.
edit: yes you have to use PUT IMAGE command any time you want to stamp it on screen otherwise the computer can't know WHERE or WHICH image you want to display.
Their variable names must be different, so "bgg" for the first image and maybe "bg2" for the second.
bgg := LOAD IMAGE("testp.png")
bg2 := LOAD IMAGE("loveu2p.png")
Then you PUT IMAGE bgg AT 0,0 for the first and PUT IMAGE bg2 AT 0,0 for the second.
You can add a WAIT KEY command in-between them so it only advances when any key is pressed.
edit: yes you have to use PUT IMAGE command any time you want to stamp it on screen otherwise the computer can't know WHERE or WHICH image you want to display.
Re: unexpected
thanks. ok it getting fixed but i notice no matter what key i press it goes line 27.i tried changing line 24 to if k = "n" but same result. OH, I added a locate which helps the text be shown!
2 CLS
4 bgg := LOAD IMAGE("testp.png")
6 bg2 := LOAD IMAGE("loveu3p.png")
11 PRINT LOCATE$(0,16); "itworks"
12 PUT IMAGE bgg AT 0,0
13 WAIT KEY
20 k = INKEY$
22 IF k = "" THEN GOTO 13
23 IF k = "Y" THEN GOTO 13
24 IF k <> "N" THEN GOTO 27
25 GOTO 13
27 CLS
28 PRINT LOCATE$(0,16); "worksw orksworkswo works alot of text sfsffsf jhkhk kjh jrksworks"
30 PUT IMAGE bg2 AT 0,0
2 CLS
4 bgg := LOAD IMAGE("testp.png")
6 bg2 := LOAD IMAGE("loveu3p.png")
11 PRINT LOCATE$(0,16); "itworks"
12 PUT IMAGE bgg AT 0,0
13 WAIT KEY
20 k = INKEY$
22 IF k = "" THEN GOTO 13
23 IF k = "Y" THEN GOTO 13
24 IF k <> "N" THEN GOTO 27
25 GOTO 13
27 CLS
28 PRINT LOCATE$(0,16); "worksw orksworkswo works alot of text sfsffsf jhkhk kjh jrksworks"
30 PUT IMAGE bg2 AT 0,0
Re: unexpected
line 24 with:
IF k="N" THEN GOTO 27
Should only show next image and text if N is pressed.
Which computer are you doing that for?
IF k="N" THEN GOTO 27
Should only show next image and text if N is pressed.
Which computer are you doing that for?
Re: unexpected
thank you all. that fixes it. Im doing tests on my personal favorite the c64, but hope to have it for others too. my idea was make a full program then test on other platforms, but is it better to test on others as i go along. Just tried for ZX nothing happened.. thanks.
Re: unexpected
Nice.
That is one approach, to test on other platforms occasionally.
I have been preferring to do COCO 1/2 stuff only but will soon tackle ZX, MSX and GB, but with different "starting" projects.
The current ones I have have too much COCO 1/2 specific stuff to work somewhere else without a lot of changes
That is one approach, to test on other platforms occasionally.
I have been preferring to do COCO 1/2 stuff only but will soon tackle ZX, MSX and GB, but with different "starting" projects.
The current ones I have have too much COCO 1/2 specific stuff to work somewhere else without a lot of changes
