BBC BASIC for Windows
« First name + second name input strings »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:46pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: First name + second name input strings  (Read 1006 times)
TobyWhaymand
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx First name + second name input strings
« Thread started on: Dec 6th, 2013, 10:34pm »

Hi guys

Firstly let me apologise for deleting my last post. A lot of the text in the game (the program) I'm writing come from my novella which isn't officially published yet I was just bit nervous about exposing too much. The game is a different story to the book but I'm writing the game for promotional purposes. I might Open Source the code but with the condition that the game stays true to the book.

Enough of me rambling... I'm stuck on something that I know is credibly simple... I want player to type in their full name on one line, for example 'Toby Whaymand'
But I want the computer to know that 'Toby and 'Whaymand' are two different words, so that during game play I can call the player either 'Toby Whaymand' or just Toby, for example.

I don't want the player have to type something like 'John' then having to press enter to type 'Smith' - There must be a way for the player to be able to type in his full name on one line and for the computer to know that it's two words, two forms of non numeric input.

Thank you SO much in advance!!


smiley
User IP Logged

ady
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 55
xx Re: First name + second name input strings
« Reply #1 on: Dec 6th, 2013, 11:59pm »

If you run a search along the letters of the full name looking at the code until the space between the names then get the program to differentiate

john smith

Look for ASC in the BB4W helpfile

The code for a space is 32
« Last Edit: Dec 7th, 2013, 12:02am by ady » User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: First name + second name input strings
« Reply #2 on: Dec 7th, 2013, 07:53am »

on Dec 6th, 2013, 10:34pm, TobyWhaymand wrote:
There must be a way for the player to be able to type in his full name on one line and for the computer to know that it's two words, two forms of non numeric input.

Of course there is - (virtually) every BASIC has the INSTR function which is perfect for this:

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin5.html#instr

Code:
      INPUT "Enter your full name: " fullname$
      space% = INSTR(fullname$, " ")
      PRINT "Your forename is "; LEFT$(fullname$, space%-1)
      PRINT "Your surname is "; MID$(fullname$, space%+1) 

If this was an exercise, I'd ask you to extend the code to detect and report if the user enters one or more middle names.

Richard.
User IP Logged

Malvern
Guest
xx Re: First name + second name input strings
« Reply #3 on: Dec 7th, 2013, 2:31pm »

And perhaps also strip any leading spaces.
User IP Logged

TobyWhaymand
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: First name + second name input strings
« Reply #4 on: Dec 7th, 2013, 2:52pm »

Thanks guys!! smiley You are awesome!!!
« Last Edit: Dec 7th, 2013, 3:17pm by TobyWhaymand » User IP Logged

TobyWhaymand
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: First name + second name input strings
« Reply #5 on: Dec 7th, 2013, 8:47pm »

Here the other issue. I thought a simple ONERRORPROCerror: GOTO 120 was the answer but that didn't seem to work.

The below is test code. I've removed sensitive wording that relate to my yet to be published novella so that I'm happy to keep this on here. I think you can see what I was trying to do... If the password matched you continued playing the game if it didn't it was game over. The user is given the password before he or she starts playing. - It's not really security thing rather part of the fun.

10 PRINT"Please enter your full name:"
20 INPUT fullname$
30 space% = INSTR(fullname$, " ")
40 PRINT "Captain "; LEFT$(fullname$, space%-1); MID$(fullname$,space%+1)
50 WAIT 100
60 PRINT""
70 PRINT""
80 INPUT"SECURITY CODE REQUIRED:";CODE$
90 IF CODE$="6ECBN98RJ9S" THEN PRINT"Good evening Captain"; MID$(fullname$,space%+1)
PRINT"We are awaiting your transportation Earth"
100 OR IF CODE$=FALSE GOTO 120
120 PRINT"PERMISSION to transport to Earth denied"
« Last Edit: Dec 7th, 2013, 8:54pm by TobyWhaymand » User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: First name + second name input strings
« Reply #6 on: Dec 7th, 2013, 10:13pm »

on Dec 7th, 2013, 8:47pm, TobyWhaymand wrote:
Here the other issue.

Sadly you neglected to say what the "issue" is. sad

Incidentally something has got garbled in your listing, because line 100, as shown, is gibberish and will simply give rise to a 'Syntax error'.

Please try to avoid using GOTOs!

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: First name + second name input strings
« Reply #7 on: Dec 8th, 2013, 12:58pm »

on Dec 8th, 2013, 09:40am, ady wrote:
90 IF CODE$="6ECBN98RJ9S" THEN PRINT"Good evening Captain"; MID$(fullname$,space%+1)
PRINT"We are awaiting your transportation Earth"
100 ELSE GOTO 120
101 ENDIF
120 PRINT"PERMISSION to transport to Earth denied"

This won't work at all (and it contains a GOTO!). I really don't think it is helpful to the OP to list broken code that quite obviously hasn't been tested. Please, in future, before posting any code, at least check that it works.

Richard.
User IP Logged

TobyWhaymand
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: First name + second name input strings
« Reply #8 on: Dec 8th, 2013, 2:52pm »

I did test the code and it didn't work which why I posted it on here. I could'nt figure out why.

In this part of the game if the user typed in the wrong password that was given to them earlier, it was game over. If they type in the correct password they continued playing.

I don't know why you dislike the GOTO command? Isn't that a popular command? I'm sure your about to tell me the reasons why ;-)

Thanks

Toby

My real focus is on my novella, the game is just a promotional thing. I will probably Open Source the game once it's written to a reasonable level. I'm really surprised that I've ready used 2K of memory. - I'm guessing that most of my code could be written more smartly, using less resources but I'm not going to worry about that at the moment.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: First name + second name input strings
« Reply #9 on: Dec 8th, 2013, 4:14pm »

on Dec 8th, 2013, 2:52pm, TobyWhaymand wrote:
I don't know why you dislike the GOTO command? Isn't that a popular command? I'm sure your about to tell me the reasons why ;-)

This topic comes up regularly, and it usually triggers heated arguments, so I'm loathe to address it again. Suffice it to say that Dijkstra's famous dissertation GOTO statement considered harmful was published in 1968, and we are now well into the 21st century!

Presumably you've worked through the Beginners' Tutorial (if not I would strongly urge you to do so) so you should have seen this: Line numbers and the dreaded GOTO. The author, Peter Nairn, takes a more relaxed view than I do; I am very much in the camp of believing that you should never, ever, use GOTO!

Putting to one side the philosophical arguments, the practical issue is that GOTO is (by design) very slow in BBC BASIC, so if you care about performance it should be avoided for that reason if no other. Also you cannot use GOTO in INSTALLed modules, so any program large enough to benefit from being split up has to avoid it.

Richard.
« Last Edit: Dec 8th, 2013, 4:18pm by admin » User IP Logged

JGHarston
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 52
xx Re: First name + second name input strings
« Reply #10 on: Dec 10th, 2013, 3:36pm »

There's also the practical issue that without GOTOs the code is easier to read and maintain.

I'm not sure what you're trying to do with your code as you've:
a) attempted to use OR as a command - it's an operator, eg fred=1 OR jim=2
b) you've attempted to compare a string to a number

but this may be what you're trying to do. Note how the structure is immediately obvious without the existence of GOTOs.
IF CODE$="6ECBN98RJ9S" THEN
PRINT "Good evening Captain ";MID$(fullname$,space%+1);"."
PRINT "We are awaiting your transportation Earth."
ELSE
PRINT "PERMISSION to transport to Earth denied."
ENDIF
Also, consider what happens if fullname$ is
"  Fred     Bloggs   "

« Last Edit: Dec 10th, 2013, 3:41pm by JGHarston » User IP Logged

hellomike
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 46
xx Re: First name + second name input strings
« Reply #11 on: Dec 10th, 2013, 8:31pm »

Or consider what happens if user enters

  6ecbn98rj9s

for security code...
User IP Logged

TobyWhaymand
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: First name + second name input strings
« Reply #12 on: Dec 13th, 2013, 7:30pm »

I did think about it but I'm not that good! LOL smiley

At the moment I just want to keep it simple so that if the user types in the correct code he can beam down to Earth if he doesn't it's game over! I will open source the game eventually.

I know enough to write a decent game but when I try and be bold like trying to tell the computer that a random input should go to a certain line of code that where I get hickory pickory and Mr Beep displays his syntax errors

I can say that I'm at a intermediate level with my BBC BASIC skill but I still got a fair bit to learn. smiley I used to write code when I was 10 years old and recently thanks to BBC BASIC for Windows I've progressed a lot over the last year. I never really forgotten those codes from way back then. (I'm 36 now) - Thanks Richard!!!
cheesy
« Last Edit: Dec 15th, 2013, 10:20am by TobyWhaymand » User IP Logged

Kirkkaf13
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 28
xx Re: First name + second name input strings
« Reply #13 on: Dec 14th, 2013, 08:47am »

Hi Toby,

You are currently grading yourself to be "high intermediate" when it comes to programming, this is not to discorage you in any way but you are correct that you have much to learn, and it concerns me that you are unfamilar with the basic fundamentals of conditional statements.

The IF command is the start of a conditional statement, to test if a expression is true or false.

Code:
IF AGE% => 18 THEN
           PRINT "You are older enough to vote."
ELSE
           PRINT "You are too young to vote."
ENDIF
 


As per line 100 of your code you have started with OR which can only be used within the expression like so:

Code:
IF AGE% = 18 OR AGE% = 21 THEN
           PRINT "You are either 18 or 21 years old."
ELSE
           PRINT "I am not sure how old you are."
ENDIF
 


So if either AGE% = 18 or AGE% = 21 then the first statement is evaluated as TRUE. If FALSE then the default ELSE is.

I am in no means an expert when it comes to programming but these are the basics of any programming language.

Also in regards to GOTO imagine if your program consists of 100,000 lines and on line 100 you told your program to GOTO line 97,461; You will have to scroll all the way through your program to find out what happens next, its a mammoth task just running through your program.

You will need to add some structure to it, have a look at defining your own functions.

Kind regards,

Kirk
User IP Logged

TobyWhaymand
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: First name + second name input strings
« Reply #14 on: Dec 14th, 2013, 1:40pm »

Thanks guys

I'm just trying to use the password in the same way somebody would use their PIN number in a cash machine...

If you type in the correct PIN you can withdraw your money

If you type an incorrect PIN number you cannot withdraw your money.

I don't need to work with variable because it's either YES or NO.

I tried have tried all the code you guys have written above and have written like that myself but I'm still getting syntax and no such variable errorshuh

I don't mine sharing code on request it just my novella isn't published yet, it going though the final stages and I'm using the universe that I created as a guideline. In the book you would actually say the the password. - I'm keeping this game retro.

Thanks again for your help smiley
« Last Edit: Dec 14th, 2013, 9:00pm by TobyWhaymand » User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls