Hi Im following a zx basic tutorial with this code:
99 CLS
100 LET y=10: LET x=15
120 LET a$=INKEY$
130 IF a#="P" AND x<=31 THEN LET x=x+1
140 IF a#="o" AND x>=0 THEN LET x=x-1
170 PRINT AT y,x; "A"
but error says unexpected let, expecting end of file. I looked in ugbasic keywords section but i dont see let? any advise thanks
LET?
-
- Site Admin
- Posts: 207
- Joined: Fri Oct 06, 2023 8:25 pm
Re: LET?
Hi zartan917!
On the other hand, since the LET command belongs to the BASIC command dictionary anyway, I decided to use this keyword to highlight simplified assignments, which allow you to optimize the code produced. On some video games, this technique can reduce the code produced by 30% to 50%, because you tell the compiler exactly what you want, creating fewer temporary copies of values. This command is available on beta branch.
Anyway, this is the translation in ugBASIC of the ZX Basic program (it cannot be translated directly, since it gives a different behaviour on standard BASIC commands, since ZX Basic is not standard):
Written like this, however, it is not very efficient. The reason is simple: the INKEY$ command generates a string that contains only one character, which is the pressed key. Then, you compare two entire string (made of a total of 2 bytes each) to update che coordinates. Since you use it to move a character and not to write a text, the best thing is to read the state of the keys directly. Try this version, which is more efficient.
I would like to point out that the ugBASIC language is not fully compatible with ZX Basic, due to specific features of the latter, which sometimes deviate from standard BASIC. I.e., PRINT AT is not standard. Therefore, it is necessary to adapt the tutorials to work with ugBASIC.
The error is correct, since LET is not currently supported on the main branch. Infact, the LET command in BASIC was originally introduced to make the assignment of a value to a variable explicit. In ZX BASIC, it was necessary to use the LET keyword before an assignment statement. In ugBASIC it does not. As many other programming languages, it does not require an explicit assignment keyword, and this made ugBASIC more concise and easier to write and read. The statement x = 5 is clearly an assignment, so the LET keyword is redundant, and removing it makes the language more accessible to beginners.
On the other hand, since the LET command belongs to the BASIC command dictionary anyway, I decided to use this keyword to highlight simplified assignments, which allow you to optimize the code produced. On some video games, this technique can reduce the code produced by 30% to 50%, because you tell the compiler exactly what you want, creating fewer temporary copies of values. This command is available on beta branch.
Anyway, this is the translation in ugBASIC of the ZX Basic program (it cannot be translated directly, since it gives a different behaviour on standard BASIC commands, since ZX Basic is not standard):
Code: Select all
99 CLS
100 y=10: x=15
120 a$=INKEY$
130 IF a$="p" AND x<=31 THEN x=x+1
140 IF a$="o" AND x>=0 THEN x=x-1
170 LOCATE x, y: PRINT "A";
180 GOTO 120
Code: Select all
99 CLS
100 y=10: x=15
130 IF KEY STATE(KEY P) AND x<=31 THEN x=x+1
140 IF KEY STATE(KEY O) AND x>=0 THEN x=x-1
170 LOCATE x, y: PRINT "A";
180 GOTO 130
Re: LET?
thank you for the explanations. I was trying to follow a tutorial to make a *simple* sidescrolling platformer game. I'm not sure if c64 would work or if there can be a link to some working platformer example. Thanks again for clearing things up.