Why is this in error?
-
- Dizzy
- Posts: 94
- Joined: Thu Feb 22, 2018 3:27 pm
- Location: virginias eastern shore
- Contact:
Why is this in error?
LET x= (10,5)
I thought that the comma would maybe perform a math function? If not then why couldn't x equal a screen position I will later call.
The ? cursor flashes right after the 0 and before the comma so why doesnt it like the zero?
I thought that the comma would maybe perform a math function? If not then why couldn't x equal a screen position I will later call.
The ? cursor flashes right after the 0 and before the comma so why doesnt it like the zero?
0 x
Re: Why is this in error?
You cannot assign a pair of values to a variable. Variables can hold only a single number. So you need two variables, X and Y.
LET X=10
LET Y=5
(Actually in modern programming languages you have "objects" and "structures" and lot of different data types so something
similar to your goal would be possible. But I assume we talk about Spectrum Basic here).
LET X=10
LET Y=5
(Actually in modern programming languages you have "objects" and "structures" and lot of different data types so something
similar to your goal would be possible. But I assume we talk about Spectrum Basic here).
1 x
- Ast A. Moore
- Dynamite Dan
- Posts: 1224
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Why is this in error?
Did you, by any chance, mean this?
This will return the attribute value at that screen position.
Code: Select all
LET x= ATTR (10,5)
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
-
- Dizzy
- Posts: 94
- Joined: Thu Feb 22, 2018 3:27 pm
- Location: virginias eastern shore
- Contact:
Re: Why is this in error?
Thanks Ralf.
Ast.A.Moore I copied that line from an example of code Scottie put up at WoS. As per this:-
let res=AddThenSquare (10,5)
Then I tried to work out what it did
Best guess is it says ' Let the result equal Add then square 10 plus 5'
So that would be 10+5=15
15x15=225
Finally I tried entering it into Fuse and got that error which baffled me.
Ast.A.Moore I copied that line from an example of code Scottie put up at WoS. As per this:-
let res=AddThenSquare (10,5)
Then I tried to work out what it did
Best guess is it says ' Let the result equal Add then square 10 plus 5'
So that would be 10+5=15
15x15=225
Finally I tried entering it into Fuse and got that error which baffled me.
0 x
- Ast A. Moore
- Dynamite Dan
- Posts: 1224
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Why is this in error?
Wait, I’m confused. Scottie gave an example in JavaScript and you’re trying to type it into the Sinclair BASIC interpreter? The syntax is completely different. I mean, you’ll need to either define a function, or spell it out right in the LET statement:llewelyn wrote: ↑Thu Aug 15, 2019 10:05 amI copied that line from an example of code Scottie put up at WoS. As per this:-
let res=AddThenSquare (10,5)
Then I tried to work out what it did
Best guess is it says ' Let the result equal Add then square 10 plus 5'
So that would be 10+5=15
15x15=225
Finally I tried entering it into Fuse and got that error which baffled me.
Code: Select all
LET x=(a+b)^2
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
-
- Dizzy
- Posts: 94
- Joined: Thu Feb 22, 2018 3:27 pm
- Location: virginias eastern shore
- Contact:
Re: Why is this in error?
I know it was a stupid thing to do. I did it out of desperation because I wondered if the comma had some weird math function I was unaware of. Yes I knew it was JavaScript that Scotties example was in but still the math should be the same whatever the language?
0 x
- Ast A. Moore
- Dynamite Dan
- Posts: 1224
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Why is this in error?
Well, it is. The syntax and structure, however, are completely different. He defined a new function and called it addThenSquare. The syntax implies that the function take two arguments in parentheses, separated by a comma:
Code: Select all
let res = addThenSquare(10,5)
The function itself is defined like this:
Code: Select all
function addThenSquare(n1, n2){
let result = n1 + n2;
result = result * result;
return result;
}
Code: Select all
LET res=(n1+n2)^2
Code: Select all
10 DEF FN a(x,y)=(x+y)^2
20 LET res= FN a(10,5)
30 PRINT res
Code: Select all
10 DEF FN a(x,y)=(x+y)^2
20 PRINT FN a(10,5)
1 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
-
- Dizzy
- Posts: 94
- Joined: Thu Feb 22, 2018 3:27 pm
- Location: virginias eastern shore
- Contact:
Re: Why is this in error?
You are a good man Mr Moore for bothering to explain things in detail so that I can understand them and I really appreciate it. Thank you.
I must find some way to save and index all the advice people so kindly dispense for my benefit because I'm feeling like a bit of Basic might not go amiss, if only to keep my brain from seizing up! Some of these tips are absolutely invaluable.
The above sincere thanks applies to everyone else who has offered advice & encouragement.
I must find some way to save and index all the advice people so kindly dispense for my benefit because I'm feeling like a bit of Basic might not go amiss, if only to keep my brain from seizing up! Some of these tips are absolutely invaluable.
The above sincere thanks applies to everyone else who has offered advice & encouragement.
0 x
- 1024MAK
- Manic Miner
- Posts: 533
- Joined: Wed Nov 15, 2017 2:52 pm
- Location: Sunny Somerset in the U.K. in Europe
Re: Why is this in error?
The BASIC programming language likes things to be built from simple building blocks (*).
Mark
* Note, but more human friendly than assembly language / machine code.
Mark
* Note, but more human friendly than assembly language / machine code.
0 x
Re: Why is this in error?
When you get into the habit of forever writing:
x = my_function(a, b)
It's easy to overlook the fact that no-one seems to have written a language with - surely - the obvious syntax:
(x, y) = my_function(a, b, c, d)
Such that a function can return more than one value.
C has lots of ways around this issue (you can define 'x' as a structure (or template) made up of two variables, and the function can return a matching structure; or you can make one of the parameters a pointer to where your variable is stored in memory, so the function can manipulate it directly) but it doesn't have a simple syntax to express it like this.
x = my_function(a, b)
It's easy to overlook the fact that no-one seems to have written a language with - surely - the obvious syntax:
(x, y) = my_function(a, b, c, d)
Such that a function can return more than one value.
C has lots of ways around this issue (you can define 'x' as a structure (or template) made up of two variables, and the function can return a matching structure; or you can make one of the parameters a pointer to where your variable is stored in memory, so the function can manipulate it directly) but it doesn't have a simple syntax to express it like this.
0 x