News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_xubuntu

questions concerning locomotive basic

Started by xubuntu, 10:21, 05 March 21

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

xubuntu

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




Gryzor

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!

eto

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

xubuntu


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.

Sykobee (Briggsy)

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);

xubuntu

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.




andycadley

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.

eto


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$

goksteroo

#8
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

xubuntu

#9
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

demoniak

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

goksteroo

#11
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.

eto


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


goksteroo

#13
:doh: DOH!! mid$(a$,i,1); is much better programming than my LEFT$ - I'm getting old, and sober.

xubuntu

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

goksteroo

#15
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

Animalgril987

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.

goksteroo

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.

Animalgril987

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:

xubuntu

#19

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)

Animalgril987


goksteroo

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.

xubuntu

#22
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)

Animalgril987

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.

xubuntu




I added the line and ...


D:\PROGRAMS\CPCBasic>cpcbasic angelo.bas /cpc:464 /out:cdt /real:1
Unsupported command in line 1 position 3

Powered by SMFPacks Menu Editor Mod