unexpected

This forum is dedicated to those who want support programming in ugBASIC.
Questo forum è dedicato a chi desidera supporto per programmare in ugBASIC.
Ce forum est dédié à ceux qui souhaitent prendre en charge la programmation en ugBASIC.
Post Reply
zartan917
Posts: 10
Joined: Fri Mar 28, 2025 1:42 pm

unexpected

Post by zartan917 »

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??
spotlessmind1975
Site Admin
Posts: 207
Joined: Fri Oct 06, 2023 8:25 pm

Re: unexpected

Post by spotlessmind1975 »

Hi zartan917, and welcome! :D
zartan917 wrote: Thu Apr 10, 2025 4:30 am but syntax error, unexpected K, expecting end of file. What can I do to fix??
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"
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. ;)
zartan917
Posts: 10
Joined: Fri Mar 28, 2025 1:42 pm

Re: unexpected

Post by zartan917 »

hi thank you. I pasted code now getting unexected OP_GT whatever that is. I didnt see where to add colons? after the thens?
spotlessmind1975
Site Admin
Posts: 207
Joined: Fri Oct 06, 2023 8:25 pm

Re: unexpected

Post by spotlessmind1975 »

Hi zartan917!
zartan917 wrote: Fri Apr 11, 2025 3:28 am hi thank you. I pasted code now getting unexected OP_GT whatever that is.
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.
zartan917 wrote: Fri Apr 11, 2025 3:28 am I didnt see where to add colons? after the thens?
This could be an example (on a single line):

Code: Select all

IF cond THEN: ... :ELSE: ... :ENDIF
This could be the same example (on multiple lines):

Code: Select all

IF cond THEN
    ... 
ELSE
   ...
ENDIF
zartan917
Posts: 10
Joined: Fri Mar 28, 2025 1:42 pm

Re: unexpected

Post by zartan917 »

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
User avatar
ericomont
Posts: 33
Joined: Sun Oct 08, 2023 11:31 am

Re: unexpected

Post by ericomont »

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.
zartan917
Posts: 10
Joined: Fri Mar 28, 2025 1:42 pm

Re: unexpected

Post by zartan917 »

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
User avatar
ericomont
Posts: 33
Joined: Sun Oct 08, 2023 11:31 am

Re: unexpected

Post by ericomont »

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?
zartan917
Posts: 10
Joined: Fri Mar 28, 2025 1:42 pm

Re: unexpected

Post by zartan917 »

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.
User avatar
ericomont
Posts: 33
Joined: Sun Oct 08, 2023 11:31 am

Re: unexpected

Post by ericomont »

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 :)
Post Reply