News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

LOCATE command in BASIC

Started by zeropolis79, 06:54, 14 February 25

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

zeropolis79

Is there a limit as to how many times you can use the LOCATE command on a line in BASIC?

I'm trying to use the PEN and LOCATE commands in a remake of a BASIC adventure from the BBC but the the first line. in which I use two LOCATE commands in the same line, the second one doesn't work.

LOCATE 14,1 works but LOCATE 29,1 won't, taking the text for it to the next line. I've tried to spread it over different lines but sadly no go.

Am I doing something wrong or is it a limitation?

Thanks

pelrun

Why use LOCATE at all, when you can just add a semicolon to the print statements so they don't automatically append a newline?

McArti0

Third print is too long.
Try first and second print ending ; and not use locate
CPC 6128, Whole 6128 and Only 6128, with .....
NewPAL v3 for use all 128kB RAM by CRTC as VRAM
One chip drver for 512kB extRAM 6128
TYPICAL :) TV Funai 22FL532/10 with VGA-RGB-in.

zeropolis79

A friend suggested the semi-colons - i took out the LOCATE commands and put ; instead of : but ended up with a Syntax Error.

I can't upload a picture but this is what the line looked like:

1010 PRINT"You are in a ";PEN 2:PRINT"lovely garden. ";PEN 1:PRINT"A note on the door says: "

or with all :'s replaced with ;

1010 PRINT"You are in a ";PEN 2;PRINT"lovely garden. ";PEN 1;PRINT"A note on the door says: "

I've even tried putting each part of the text to be printed on separate lines but no go. It's the same with or without the : in the final printed line.



eto

Semikolon after the print command. But then you still need the colon to separate commands.

Print "a";:pen 2:print "b"

zeropolis79


andycadley

FWIW, LOCATE can be used multiple times in a line just fine. The problem is Locomotive BASIC is very finicky about where a PRINT starts. If it decides there isn't enough room on the current line, it'll always start a new one even if the previous PRINT ended with a ;

I have a vague feeling you can avoid it by doing ZONE 255 as long as you aren't relying on , in your PRINT statements. 

eto

Indeed... I remember that this annoyed me a lot in the 80s. Is there any way to force BASIC to continue printing? 

Attached is the comment in the manual. 

andycadley

Like I say, I think issuing ZONE 255 first, which makes the "print zone" as big as it can be, mostly makes the issue go away - although I don't think it was a perfect solution, but the details are foggy. Embedding control codes in a string so you don't need multiple PRINT statements can help too, but obviously then the limit of 255 characters per string becomes more of a problem.

eto

I just found out how it can be done. You can add control codes to your output instead of locate - and then it always starts printing at the position.

(I use a$ but it can also be a static text like in the first post here)

10 locate 5,10:print a$

can also be expressed as

10 print chr$(31)+chr$(5)+chr$(10)+a$

However it behaves differently, if a$ is longer than the rest of the line. In the first case it will be moved into the next line. In the second case it will still start at 5,10 and print as expected.

Also you must use + and not ; as with a ; it will again start in the next line.

eto

Quote from: andycadley on 09:46, 14 February 25Like I say, I think issuing ZONE 255 first, which makes the "print zone" as big as it can be, mostly makes the issue go away - although I don't think it was a perfect solution, but the details are foggy. Embedding control codes in a string so you don't need multiple PRINT statements can help too, but obviously then the limit of 255 characters per string becomes more of a problem.
I just tried and I don't see a change in behaviour with "ZONE 255"

zeropolis79


McArti0

CTRL+A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z

give ASCI 1,2,3,4,5,6,7,8,9,.......................................,26
CPC 6128, Whole 6128 and Only 6128, with .....
NewPAL v3 for use all 128kB RAM by CRTC as VRAM
One chip drver for 512kB extRAM 6128
TYPICAL :) TV Funai 22FL532/10 with VGA-RGB-in.

ZorrO

ZONE affects what spacing will be after using a comma. It doesn't work on LOCATE, or place after ;

@eto - In your example, plus sign is only necessary before a$, and pluses between CHR$ are unnecessary.

There is another way to make long texts start by LOCATE close to right margin:
LOCATE 35,10:PRINT USING"&";"long text"
CPC+PSX 4ever

andycadley

Clearly a false memory on my part. I know it wasn't long before I ended up writing various text routines of my own, so it may be one of the reasons why. I did think there was some sort of simple workaround though, but maybe I've just forgotten.

zeropolis79

Thanks all - the next thing to do is put all the room descriptions into arrays as to make it more authentic to the BBC original, I'm going to use double height text..

zeropolis79

Due to some unrelated issues with BASIC, the BASIC version of the game is on hold and the whole thing is being done in GAC instead..

Powered by SMFPacks Menu Editor Mod