Author Topic: questions concerning locomotive basic  (Read 2165 times)

0 Members and 1 Guest are viewing this topic.

Offline xubuntu

  • CPC464
  • **
  • Posts: 27
  • Country: gr
    • Awards
questions concerning locomotive basic
« on: 11: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



like
0
No reactions
cpc power

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 17.099
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
    • Awards
Re: questions concerning locomotive basic
« Reply #1 on: 11:27, 05 March 21 »
Hi


and welcome me to the forum.



Your wish is my command: welcome to the forum!
like
0
No reactions

Offline eto

  • Supporter
  • 464 Plus
  • *
  • Posts: 451
  • Country: de
    • Awards
Re: questions concerning locomotive basic
« Reply #2 on: 11:39, 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
like
0
No reactions

Offline xubuntu

  • CPC464
  • **
  • Posts: 27
  • Country: gr
    • Awards
Re: questions concerning locomotive basic
« Reply #3 on: 16: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.
like
0
No reactions
cpc power

Offline Sykobee (Briggsy)

  • 6128 Plus
  • ******
  • Posts: 845
  • Country: gb
    • Awards
Re: questions concerning locomotive basic
« Reply #4 on: 17: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);
like
0
No reactions

Offline xubuntu

  • CPC464
  • **
  • Posts: 27
  • Country: gr
    • Awards
Re: questions concerning locomotive basic
« Reply #5 on: 19: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.



like
0
No reactions
cpc power

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.005
    • Awards
Re: questions concerning locomotive basic
« Reply #6 on: 20: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.
like
0
No reactions

Offline eto

  • Supporter
  • 464 Plus
  • *
  • Posts: 451
  • Country: de
    • Awards
Re: questions concerning locomotive basic
« Reply #7 on: 00:12, 06 March 21 »

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

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

Code: [Select]
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$
like
0
No reactions

Offline goksteroo

  • CPC464
  • **
  • Posts: 25
  • Country: au
    • Awards
Re: questions concerning locomotive basic
« Reply #8 on: 03: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....
Code: [Select]
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
« Last Edit: 04:05, 06 March 21 by goksteroo »
like
0
No reactions

Offline xubuntu

  • CPC464
  • **
  • Posts: 27
  • Country: gr
    • Awards
Re: questions concerning locomotive basic
« Reply #9 on: 09: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
« Last Edit: 09:11, 06 March 21 by xubuntu »
like
0
No reactions
cpc power

Offline demoniak

  • CPC664
  • ***
  • Posts: 107
  • Country: fr
    • Awards
Re: questions concerning locomotive basic
« Reply #10 on: 10:43, 06 March 21 »
Little adaptation of your code :
Code: [Select]
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
like
0
No reactions

Offline goksteroo

  • CPC464
  • **
  • Posts: 25
  • Country: au
    • Awards
Re: questions concerning locomotive basic
« Reply #11 on: 11: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@!).
Code: [Select]
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.
« Last Edit: 11:25, 06 March 21 by goksteroo »
like
0
No reactions

Offline eto

  • Supporter
  • 464 Plus
  • *
  • Posts: 451
  • Country: de
    • Awards
Re: questions concerning locomotive basic
« Reply #12 on: 11:29, 06 March 21 »

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


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)

Code: [Select]
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
like
0
No reactions

Offline goksteroo

  • CPC464
  • **
  • Posts: 25
  • Country: au
    • Awards
Re: questions concerning locomotive basic
« Reply #13 on: 11:36, 06 March 21 »
:doh: DOH!! mid$(a$,i,1); is much better programming than my LEFT$ - I'm getting old, and sober.
« Last Edit: 11:39, 06 March 21 by goksteroo »
like
0
No reactions

Offline xubuntu

  • CPC464
  • **
  • Posts: 27
  • Country: gr
    • Awards
Re: questions concerning locomotive basic
« Reply #14 on: 15: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
like
0
No reactions
cpc power

Offline goksteroo

  • CPC464
  • **
  • Posts: 25
  • Country: au
    • Awards
Re: questions concerning locomotive basic
« Reply #15 on: 16: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
« Last Edit: 16:46, 06 March 21 by goksteroo »
like
0
No reactions

Offline Animalgril987

  • Supporter
  • CPC6128
  • *
  • Posts: 230
  • Country: gb
    • Awards
Re: questions concerning locomotive basic
« Reply #16 on: 16: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.
like
0
No reactions

Offline goksteroo

  • CPC464
  • **
  • Posts: 25
  • Country: au
    • Awards
Re: questions concerning locomotive basic
« Reply #17 on: 16:42, 06 March 21 »
Quote
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.
like
0
No reactions

Offline Animalgril987

  • Supporter
  • CPC6128
  • *
  • Posts: 230
  • Country: gb
    • Awards
Re: questions concerning locomotive basic
« Reply #18 on: 18:17, 06 March 21 »
Quote (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:
like
0
No reactions

Offline xubuntu

  • CPC464
  • **
  • Posts: 27
  • Country: gr
    • Awards
Re: questions concerning locomotive basic
« Reply #19 on: 18: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)
« Last Edit: 18:47, 06 March 21 by xubuntu »
like
0
No reactions
cpc power

Offline Animalgril987

  • Supporter
  • CPC6128
  • *
  • Posts: 230
  • Country: gb
    • Awards
Re: questions concerning locomotive basic
« Reply #20 on: 19:29, 06 March 21 »
Happy to be of assistance :D
like
0
No reactions

Offline goksteroo

  • CPC464
  • **
  • Posts: 25
  • Country: au
    • Awards
Re: questions concerning locomotive basic
« Reply #21 on: 03:13, 07 March 21 »
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?

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.

I 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.
like
0
No reactions

Offline xubuntu

  • CPC464
  • **
  • Posts: 27
  • Country: gr
    • Awards
Re: questions concerning locomotive basic
« Reply #22 on: 15: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)
« Last Edit: 15:05, 13 March 21 by xubuntu »
like
0
No reactions
cpc power

Offline Animalgril987

  • Supporter
  • CPC6128
  • *
  • Posts: 230
  • Country: gb
    • Awards
Re: questions concerning locomotive basic
« Reply #23 on: 17: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.
like
0
No reactions

Offline xubuntu

  • CPC464
  • **
  • Posts: 27
  • Country: gr
    • Awards
Re: questions concerning locomotive basic
« Reply #24 on: 19: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
like
0
No reactions
cpc power