One liners, how to jump to different parts of the line?

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

One liners, how to jump to different parts of the line?

Post by Nomad »

While doing a basic prototype I got to thinking - how can i put in loop structures or jumps to different parts of the same line in basic? I figure its done often in things like one liners.

What I would like to do is have a flashing menu so I have something like

Code: Select all

42 LET COUNTER=0:FOR COUNTER1 TO 10:PRINT AT 11,7;"MISSILE LAUNCH":PAUSE 10:CLS:NEXT COUNTER: INK 2:PAPER 7:BORDER 7: LET COUNTER=0:FOR COUNTER1 TO 10:PRINT AT 11,7;"INCOMING":PAUSE 10:CLS:NEXT COUNTER:RETURN
User avatar
Einar Saukas
Bugaboo
Posts: 3070
Joined: Wed Nov 15, 2017 2:48 pm

Re: One liners, how to jump to different parts of the line?

Post by Einar Saukas »

Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: One liners, how to jump to different parts of the line?

Post by Nomad »

Thanks Einar; you are a star.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: One liners, how to jump to different parts of the line?

Post by Nomad »

Einar - just a quick question about Skier

Code: Select all

 LET i=(INKEY$="7" AND c<30)-(INKEY$="6" AND c>1):
 
So I think that the value i is checking inkey$ is between 7 or 6 within the range 1-30 columns.

If you needed to do up and down could extra inkey$ values be used or would a different section be needed?
User avatar
Einar Saukas
Bugaboo
Posts: 3070
Joined: Wed Nov 15, 2017 2:48 pm

Re: One liners, how to jump to different parts of the line?

Post by Einar Saukas »

Nomad wrote: Sat Mar 31, 2018 8:38 amEinar - just a quick question about Skier

Code: Select all

 LET i=(INKEY$="7" AND c<30)-(INKEY$="6" AND c>1):
 
So I think that the value i is checking inkey$ is between 7 or 6 within the range 1-30 columns.
Not exactly.

In Sinclair BASIC, a condition evaluates to 1 if true, 0 if false.

Variable i is sideways increment. If key 7 (right) is pressed and player is before column 30, then (INKEY$="7" AND c<30) will evaluate to 1, therefore variable i will be 1. It will make column position increase by 1, moving to the right.

If key 6 (left) is pressed and player is after column 1, then (INKEY$="6" AND c>1) will evaluate to 1, therefore variable i will be -1. It will make column position decrease by 1, moving to the left.

Nomad wrote: Sat Mar 31, 2018 8:38 amIf you needed to do up and down could extra inkey$ values be used or would a different section be needed?
You would need another variable for up/down increment, to update row instead of column.
Post Reply