CPCWiki forum

General Category => Programming => Topic started by: xubuntu on 10:21, 05 March 21

Title: questions concerning locomotive basic
Post by: xubuntu on 10:21, 05 March 21
Hi


and welcome me to the forum.


2 questions.


1. How do I set a max character length in the input command ? I want the user to be able to input up to 10 characters, no more.
2. Can I get rid of the question mark (?) before the input ?


thanks



Title: Re: questions concerning locomotive basic
Post by: Gryzor on 10:27, 05 March 21
Quote from: xubuntu on 10:21, 05 March 21
Hi


and welcome me to the forum.



Your wish is my command: welcome to the forum!
Title: Re: questions concerning locomotive basic
Post by: eto on 10:39, 05 March 21
Quote from: xubuntu on 10:21, 05 March 21
1. How do I set a max character length in the input command ? I want the user to be able to input up to 10 characters, no more.
2. Can I get rid of the question mark (?) before the input ?

1) afaik this is not possible, but you can easily write your own routine using Inkey$ instead
2) https://www.grimware.org/doku.php/documentations/software/locomotive.basic/start#input
Title: Re: questions concerning locomotive basic
Post by: xubuntu on 15:11, 05 March 21

Thanks for the question 1 regarding the questionmark.


Now concerning question 2..


What you proposed doesn't work (or I am just too stupid).


Because the "input" reads after the "enter" is pressed. And so the counter adds not when its supposed to (when pressing any key) but after the enter is pressed.


3190 l = 1
3195 input "input",i$
3201 q$=INKEY$:if q$="" goto 3201 else l = l + 1
3204 if l >= 20 then print "max length 20 reached": goto 3195
3300 IF i$="how are you" then print "i am ok": goto 3195
3350 print l
3360 goto 3195


If I remove line 3195, then the counter counts any pressed keys as it should.
Title: Re: questions concerning locomotive basic
Post by: Sykobee (Briggsy) on 16:03, 05 March 21
Two options:


Trim the input using LEFT$ after it has been entered.
Don't use INPUT but record character after character using INKEY$ incrementing a counter until its 10 (also need to handle delete).


So you need to handle return (character 13) to terminate early, and delete (127) to decrement the counter (and erase the printed character).

To delete and move the cursor left: print chr$(8);" ";chr$(8);
Title: Re: questions concerning locomotive basic
Post by: xubuntu on 18:26, 05 March 21
how tha f i will not use input since i am creating an AI (dum as fuk) to which you talk to and you have to type in things like "hey bot what's your name?"


your 1st option won't do either


The problem is, that once the input-er writes a few lines, my graphics go up in the screen and get messy. I don't mind the input-er being able to input many lines, but I mind that on each new line, all lines go up and they fuck up my graphics.



Title: Re: questions concerning locomotive basic
Post by: andycadley on 19:08, 05 March 21
It's not that difficult to build a custom text entry procedure that uses INKEY$ to detect when a key is pressed. This gives you a lot more flexibility over how it is displayed on screen and any additional restrictions you might want (such as limiting valid keys or the length of the acceptable input string).


If you're just worried about constraining where the INPUT occurs, you can limit the section of the screen by defining a WINDOW.
Title: Re: questions concerning locomotive basic
Post by: eto on 23:12, 05 March 21

Quote from: xubuntu on 15:11, 05 March 21What you proposed doesn't work (or I am just too stupid).

Probably just not familiar yet with Locomotive Basic....


10 PRINT "please enter up to 10 characters"
20 FOR i=1 TO 10
30 a$="":WHILE a$="":a$=INKEY$:WEND
40 PRINT a$;
50 b$=b$+a$
60 IF a$=CHR$(13) THEN i=10
70 NEXT
80 PRINT:PRINT "you entered: ";b$
Title: Re: questions concerning locomotive basic
Post by: goksteroo on 02:59, 06 March 21
Here's another - variable input length... only accepts 0-9 and A-z as input, uses backspace/delete to delete characters....
10 CLS
20 INPUT "Max characters to enter:";maxchr$:REM characters to enter 1-20
30 maxchr=VAL(maxchr$)
40 IF maxchr<1 OR maxchr>20 THEN 20:REM input length 1-20 characters
50 CLS
60 PRINT "Please enter";maxchr;"character";
70 IF maxchr>1 THEN PRINT "s: " ELSE PRINT ": "
80 l=0:b$=""
90 a$="":WHILE a$="":a$=INKEY$:WEND:REM wait for key
100 IF l=maxchr THEN 120:REM ignore characters if at max length
110 IF (a$=>"0" AND a$<="9") OR (a$=>"A" AND a$<="Z") OR (a$=>"a" AND a$<="z") THEN b$=b$+a$: LOCATE 1,5:PRINT b$:l=l+1:GOTO 90:REM accept numbers and letters only
120 IF a$=CHR$(127) AND l>0 THEN l=l-1:b$=LEFT$(b$,l):LOCATE 1,5:PRINT b$;" ";:GOTO 90:REM backspace/delete key
130 IF a$=CHR$(13) AND l>0 THEN PRINT "You entered ";l;"characters":PRINT b$:END:REM enter entered so done
140 GOTO 90
Title: Re: questions concerning locomotive basic
Post by: xubuntu on 08:08, 06 March 21
unfuckingbelievable


Thank you all 3 for the answers, they all work.


Some more questions if you don't mind:


a. What's the char/how do I create a space/gap on pressing spacebar ?


b. How do I make the replies of the bot to be printed on the screen with a small delay, letter by letter? (For aesthetic purpose, I want the bot to give answers that are typed on the screen letter after letter with a small delay of 100 miliseconds between each letter, so it feels more real.)

that's my new code


70 print "enter"
80 l=0
85 b$=""
90 a$="":WHILE a$="":a$=INKEY$:WEND
95 locate 1,5:print "                                "
100 IF l=30 THEN goto 120
110 IF (a$=>"0" AND a$<="9") OR (a$=>"A" AND a$<="Z") OR (a$=>"a" AND a$<="z") THEN b$=b$+a$: locate 1,5: PRINT b$:l=l+1:GOTO 90
120 IF a$=CHR$(127) AND l>0 THEN l=l-1:b$=LEFT$(b$,l):LOCATE 1,5:PRINT b$;" ";:GOTO 90
130 IF a$=CHR$(13) AND l>0 THEN goto 135 else goto 90
135 if b$ ="how are you" then print "i am ok"
140 GOTO 70

the bot will reply now only when the user presses enter, and i want "i am ok" to be displayed letter by letter with a small delay
Title: Re: questions concerning locomotive basic
Post by: demoniak on 09:43, 06 March 21
Little adaptation of your code :70 PRINT "enter"
80 LOCATE 1,5:PRINT "                                "
85 b$=""
90 a$="":WHILE a$="":a$=INKEY$:WEND
100 IF LEN(b$)=30 THEN GOTO 120
110 IF a$=" " OR (a$>="0" AND a$<="9") OR (a$>="A" AND a$<="Z") OR (a$>="a" AND a$<="z") THEN b$=b$+a$: LOCATE 1,5: PRINT b$:GOTO 90
120 IF a$=CHR$(127) AND LEN(b$)>0 THEN b$=LEFT$(b$,LEN(b$)-1):LOCATE 1,5:PRINT b$;" ";:GOTO 90
130 IF a$=CHR$(13) AND LEN(b$)>0 THEN GOTO 135 ELSE GOTO 90
135 IF b$ ="how are you" THEN PRINT "i am ok"
140 GOTO 70
Title: Re: questions concerning locomotive basic
Post by: goksteroo on 10:23, 06 March 21
You will now run into the problem that the user will not see that the SPACE press is not evident on the screen. I'd suggest this code to add a cursor (in mode 1 or 0 you could have it a flashing colour). Here is the delayed printing that you want as well - just change the 60 in line 1010 to speed/slow the print speed (and change the sound beep too@!).
70 PRINT "enter"
80 l=0
85 b$=""
90 a$="":WHILE a$="":a$=INKEY$:WEND
95 LOCATE 1,5:PRINT "_                                "
100 IF l=30 THEN GOTO 120
110 IF (a$>="0" AND a$<="9") OR (a$>="A" AND a$<="Z") OR (a$>="a" AND a$<="z") OR a$=" " THEN b$=b$+a$: LOCATE 1,5: PRINT b$;"_";:l=l+1:GOTO 90
120 IF a$=CHR$(127) AND l>0 THEN l=l-1:b$=LEFT$(b$,l):LOCATE 1,5:PRINT b$;"_ ";:GOTO 90
130 IF a$=CHR$(13) AND l>0 THEN GOTO 135 ELSE GOTO 90
135 IF b$ ="how are you" THEN ans$="i am ok":GOSUB 1000
140 GOTO 70
1000 FOR x=1 TO LEN(ans$):LOCATE 1,20:PRINT LEFT$(ans$,x)
1010 SOUND 1,400,3:t=TIME:WHILE TIME<t+60:WEND
1020 NEXT x:RETURN

You could also change line 110 to accept any other characters you like - question mark for example.
Title: Re: questions concerning locomotive basic
Post by: eto on 10:29, 06 March 21

Quote from: xubuntu on 08:08, 06 March 21a. What's the char/how do I create a space/gap on pressing spacebar ?


b. How do I make the replies of the bot to be printed on the screen with a small delay, letter by letter? (For aesthetic purpose, I want the bot to give answers that are typed on the screen letter after letter with a small delay of 100 miliseconds between each letter, so it feels more real.)


a) chr$(32) or just " " will print a space. Check out the ASCII table in the CPC manual. (btw: also and excellent resource for Locomotive Basic fundamentals)

b)


10 a$ = "This is a text that shall be printed one by one!"
20 for i=1 to len(a$)
30 print mid$(a$,i,1);
40 for w=1 to 100:next
50 next
60 print

Title: Re: questions concerning locomotive basic
Post by: goksteroo on 10:36, 06 March 21
:doh: DOH!! mid$(a$,i,1); is much better programming than my LEFT$ - I'm getting old, and sober.
Title: Re: questions concerning locomotive basic
Post by: xubuntu on 14:36, 06 March 21
HI. Exciting shit.

First of all thank you all, I tried all of your codes.

goksteroo your code has 2 bugs

a. when the character limits reaches, the text dissappears
b. on each key press, the whole text flashes, disappears/re-appears (if I could avoid that I might use your code)

-=-=-=-

what's the bloody difference between mid$(a$,i,1)         and        PRINT LEFT$(a$,x)   ?

I had the exact same results

-=-=-=-

NEW QUESTION!

Can I set something like:

if a$ = "*jerry*" then print "who is jerry?"

Obviously that doesn't work cause I tried it already.

What I want to do is, I want the bot to be able to spot that the input-er mentioned the word "jerry" and respond accordingly.

;D
Title: Re: questions concerning locomotive basic
Post by: goksteroo on 15:32, 06 March 21
a) The text doesn't disappears - if you get to the input count limit then no more key inputs are accepted unless those inputs are Backspace/Delete or Return/Enter. press Delete and you can enter more text.

b) The flashing text is caused by your line 95 where a whole lot of spaces are printed before b$ is printed again. Change this to line number 87 and take it out of the loop and the problem disappears.

Mid$(a$,i,1) takes one letter from the middle of the text and prints it. Left$(a$,x) takes the left most x characters from the string. They both work in this case but mid$ is neater programming.

I'd suggest you get hold of the cpc manual - here is the 6128 manual in pdf format with hypererlinks to make looking/searching easier. You can look at it online or download it.

https://vdocuments.site/amstradcpc6128-hypertext-en-sinewalker.html (https://vdocuments.site/amstradcpc6128-hypertext-en-sinewalker.html)
Title: Re: questions concerning locomotive basic
Post by: Animalgril987 on 15:34, 06 March 21
Assuming a$ ="jerry"
then this should work:


   IF INSTR(1,a$, "jerry") <>0 THEN PRINT "Who is jerry?"


I think the INSTR command is case sensitive.
Title: Re: questions concerning locomotive basic
Post by: goksteroo on 15:42, 06 March 21
QuoteI think the INSTR command is case sensitive.
Yes it is, but you could always use upper$(b$) or lower$(b$) to keep everything upper or lower case.
Title: Re: questions concerning locomotive basic
Post by: Animalgril987 on 17:17, 06 March 21
Quote from: goksteroo on 15:42, 06 March 21Quote (selected)
I think the INSTR command is case sensitive.
Yes it is, but you could always use upper$(b$) or lower$(b$) to keep everything upper or lower case.

I'd forgotten those two... :picard:
Title: Re: questions concerning locomotive basic
Post by: xubuntu on 17:35, 06 March 21

INCREDIBLE GUYS !! IT all works!

I wanna thank my mother, my father, all the guys that supported me and especially the people who brought me to this place to be able to pick up this oscar.

I noticed that while my delayed output was being printed, I was not able to print/input.

And this is a question that I have many years, while programming (wanking) with other forms of basic like Qbasic.

How can I have 2 loops simultaneously ?

Let's assume that I have a "for to" loop and I want at the same time another loop to take place and at the same time 2 inkey$ loops (because let's say 2 players are playing).

Can I have 4 total loops looping together? Can I have 2 ? How do programmers deal with this problem? Is it a problem or it's just my stupidity talking?

Thanks a lot for your help, I appreciate.

:-* :-* :-* :-* :-* :-*


Thanks for the ebook too, I downloaded it. (had to wait 1 minute on the same fuckin window, once you changed tab the counter halt)
Title: Re: questions concerning locomotive basic
Post by: Animalgril987 on 18:29, 06 March 21
Happy to be of assistance :D
Title: Re: questions concerning locomotive basic
Post by: goksteroo on 02:13, 07 March 21
Quote from: xubuntu on 17:35, 06 March 21How can I have 2 loops simultaneously ?

Let's assume that I have a "for to" loop and I want at the same time another loop to take place and at the same time 2 inkey$ loops (because let's say 2 players are playing).

Can I have 4 total loops looping together? Can I have 2 ? How do programmers deal with this problem? Is it a problem or it's just my stupidity talking?

I can't see why you'd want 2 inkey$ loops for 2 players - the command will detect any number of keys, but basically only one at a time - not ideal for an action game. In many cases you'd be better off using the INKEY command (not INKEY$) to interrogate key presses as you can interrogate many keys in the same loop and it will recognize each of many keys pressed at the same time.

As far as loops go, you can basically have as many nested as you want, but it is often not good programming unless you are doing some recursive functions like making mazes.

Quote from: xubuntu on 17:35, 06 March 21I noticed that while my delayed output was being printed, I was not able to print/input.

Can be done in several different ways... a) using interrupts to print your answers (see the EVERY and REMAIN commands). b) use the print loop to print only one character at a time - will need to be called frequently from within the inkey$ routine and will need flags for the delay, position of next printable character, etc. Both very doable.

I'd also suggest you get used of using flow charts for checking your logic/flow in your programmes - can make it easier to follow complex routines.
Title: Re: questions concerning locomotive basic
Post by: xubuntu on 14:03, 13 March 21
Hi guys

I am half way through finishing my game and i felt like it's time to test if I can move it over to my real cpc 464.

So, I download cpcbasic and the command I give is:

cpcbasic angelo.bas /cpc:464 /out:cdt /real:1

This is my testing program:

5 cls
10 print "fuck you"
15 end

So, then I open winape and I type in: |tape and run" and it says "press play and any key".... and then it seems to work as it says "loading output.bin in com 1" and restarts.

But my program is not loaded............ masterfail....

So a few questions besides the obvious (why tha fuck doesn't it work?) are:

a. How stupid am I from 0 to 10 ? Cast your vote freely!

b. Shouldn't winape say something like "loading angelo.cdt" instead of loading output.bin ? ( I tried exporting a dsk file with the same results, the file loads but not my code)

c. i tried to understand what real numbers are and it seems that I do not have ANY real number on my program (and certainly not in the testing program).. and yet the compiler (or whatever that is, the converter, whatever) asks me to set a number > 0... Are there real numbers in my program? Why all that?

d. Does cpcbasic work from the gui window ? There is no button to press in order to do the conversion, and so I used cmd.

ok those questions are enough for starters.. Don't forget to vote....
8)
Title: Re: questions concerning locomotive basic
Post by: Animalgril987 on 16:49, 13 March 21
Think the first line of your program needs to be:


1 CHAIN "CPCBASIC.BAS"


So that the CPC BASIC library is linked in.
The line number can be anything, as long as it's the FIRST line of your program.
Title: Re: questions concerning locomotive basic
Post by: xubuntu on 18:09, 13 March 21



I added the line and ...


D:\PROGRAMS\CPCBasic>cpcbasic angelo.bas /cpc:464 /out:cdt /real:1
Unsupported command in line 1 position 3
Title: Re: questions concerning locomotive basic
Post by: SRS on 20:30, 13 March 21
Well, if it is about Locomotive Basic why bother about "CPCBASIC" ?
Just paste your source to winape (CTRL-F11), save it to dsk 'save "blabla.bas"' or tape image and transfer this to CPC ?



Title: Re: questions concerning locomotive basic
Post by: xubuntu on 08:39, 14 March 21
ok so I managed to save/read from tape/wav file but i can't turn it over to dsk usage.

I create a new blank disk in drive A and then type CAT but says "read fail retry ignore cancel".

When I type "save "blank.bas" it prompts to press rec and play, which means it's still turned to the tape. How do I turn it to disk usage? Please be specific.

And with |cpm i get

Failed to load boot sector
This error shows that the command has failed and the program can't be started using the "|CPM" command.

What is going on ?
Thank you
Title: Re: questions concerning locomotive basic
Post by: Animalgril987 on 10:58, 14 March 21
Hi.
Typing |CPM. tries to boot from a SYSTEM disc, you can't use a blank disc.


Load your tape program then type this:


|DISC.OUT
SAVE"  blank.bas"


Let me know what happens.


Alan.
Title: Re: questions concerning locomotive basic
Post by: xubuntu on 13:52, 14 March 21
it says DRIVE A DISC MISSING


and then I go "new blank disc" and it again says DRIVE A READ FAIL

No matter if I load my tape program as you said, or do it from scratch, I get the same results.

Saving/loading tapes works.

Saving/loading discs doesn't.

Have I done something in the settings of winape ?
Title: Re: questions concerning locomotive basic
Post by: skylas on 16:03, 14 March 21
Try save it in this dsk blank file
Title: Re: questions concerning locomotive basic
Post by: skylas on 16:22, 14 March 21
Quote from: xubuntu on 08:08, 06 March 21


the bot will reply now only when the user presses enter, and i want "i am ok" to be displayed letter by letter with a small delay
My method for adding delay generally (maybe my method is not so right - sure there are better ways) is just:
FOR D= 1 to 1000:next d
You can change 1000 to whatever you like, depending on how mych delay you want
Title: Re: questions concerning locomotive basic
Post by: xubuntu on 17:32, 14 March 21
I think it worked Greak maestro.


What is the difference of this disk you sent in comparison to creating a "new blank disc" ?


Also, what is cartridge ? Some slot at the back of the cpc where you can storage data ? Like a disc/tape alternative ?
Title: Re: questions concerning locomotive basic
Post by: skylas on 17:38, 14 March 21
Quote from: xubuntu on 17:32, 14 March 21
I think it worked Greak maestro.


What is the difference of this disk you sent in comparison to creating a "new blank disc" ?


Also, what is cartridge ? Some slot at the back of the cpc where you can storage data ? Like a disc/tape alternative ?
Dont know exactly the difference, but i had the same problem. So, I created a blank disk by downloading a simple BASIC game disk, deleted the game, and kept this empty disk in order to copy-paste and create others.


As i know catridge is a way of storing data, such as disks and tapes, but in a shape that for example gameboy cassettes were (In Greek we calll it both Κασέτα).
Maybe 6128 plus had catridges?
Title: Re: questions concerning locomotive basic
Post by: xubuntu on 17:40, 14 March 21
and another question...

I know how to load/run a *.bas game in Winape.

I know how to load/run a *.dsk game in Winape.

How tha fak do I load a game that has a 3DQUASAR and 3DQUASAR.BIN file ?

Obviously I need to type run"3DQUASAR

But how do I load it ? Since it's not in a tape and not in a dsk... and there is no simple option to load a directory where those files are located... ?? A bloody ridle. For a stupid guy (me).
Title: Re: questions concerning locomotive basic
Post by: skylas on 18:14, 14 March 21
I know only of .BAS files, but maybe this helps?
Title: Re: questions concerning locomotive basic
Post by: goksteroo on 00:59, 15 March 21
Winape....

1) Drive A:
2) New Blank Disc - give it a name
3) Format Disc Image - select type of disc - all discs need to be formatted before use, in real life and in the WinApe world.
4) use disc - save load/whatever

You can then also select Edit Disc and drag and drop files form your windows file selector.
Title: Re: questions concerning locomotive basic
Post by: xubuntu on 06:51, 15 March 21
I told you I was stupid. Didn't I? It's a great thing to know thyself.

Goksteroo I was hoping that you will step in with an answer.

Skylas forgot to thank you too, thanks !

Goksteroo, final question (for this week)..

How do I load a program that does NOT have a dsk nor a wav in winape ?

This CPC GAMES CD Is unfuckingbelievably exciting, if I only knew how to run them. :-X
Title: Re: questions concerning locomotive basic
Post by: goksteroo on 12:28, 15 March 21
I only download .DSK for use on WinApe - and they can also be used with a Gotek like device on a real CPC. I've sent you a private message.
Geoff
Title: Re: questions concerning locomotive basic
Post by: Johnny Olsen on 19:54, 15 March 21
Quote from: xubuntu on 06:51, 15 March 21
I told you I was stupid. Didn't I? It's a great thing to know thyself.


Goksteroo, final question (for this week)..

How do I load a program that does NOT have a dsk nor a wav in winape ?

This CPC GAMES CD Is unfuckingbelievably exciting, if I only knew how to run them. :-X

You can find an explanation here.

http://www.cpcwiki.eu/index.php/CPCGamesCD-CPCLoader

Title: Re: questions concerning locomotive basic
Post by: xubuntu on 07:03, 16 March 21
ok I suppose with that tool I create dsk files from folders that contain the game in bin/other format, right ?
Powered by SMFPacks Menu Editor Mod