Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Noob question...

Author
Message
Superdean
19
Years of Service
User Offline
Joined: 18th Feb 2006
Location:
Posted: 6th Apr 2007 16:15
I have a code that looks like this:

The only problem is, how do I get it to use only numbers on the age and only letters on the name? I will be greatful if someone could help me for it will also help me later on in my game

Silent Ghost Coming Soon
[img=http://img168.imageshack.us/img168/9826/89797ok5.th.gif}
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 6th Apr 2007 16:22 Edited at: 6th Apr 2007 16:26
take off the dollar sign on cage$, so it becomes cage...

following a variable name with a $ forces the data to be a string...
likewaise, following with a # forces the data to be a float (or a decimal number)

following a number with no sign forces the data to be an integer (a whole number)

following a variable name with both a $ and # does nothing useful, and actually causes your program to not even compile...

edit: missed the second bit... only letters on the name... sorry, can't do easily... since any character at all is allowed in a string (including numbers) the computer doesn't know any better than to just accept the number as if it is supposed to be there...
Superdean
19
Years of Service
User Offline
Joined: 18th Feb 2006
Location:
Posted: 6th Apr 2007 16:24
thanks

Silent Ghost Coming Soon
[img=http://img168.imageshack.us/img168/9826/89797ok5.th.gif}
Superdean
19
Years of Service
User Offline
Joined: 18th Feb 2006
Location:
Posted: 6th Apr 2007 16:27
is there any way to make it an if/then statement? for instance i can say

if ;cage>0 then print "You are older than 0!"

Silent Ghost Coming Soon
[img=http://img168.imageshack.us/img168/9826/89797ok5.th.gif}
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 6th Apr 2007 16:40 Edited at: 6th Apr 2007 16:44
Just add the if statement after the input statement for the age.
if cage >0 then print "You are older than 0"

3.0 Ghtz/1GB DDR400 Ram/Ati 9550 256MB AGP Graphics/100GB Maxtor Sata Drive/Dark Basic Pro 6.5

Know one cares how much you know until they know how much you care.
Superdean
19
Years of Service
User Offline
Joined: 18th Feb 2006
Location:
Posted: 6th Apr 2007 16:44 Edited at: 6th Apr 2007 16:46
thanks for your help, but the attached picture happens with the new Set Cursor part.

EDIT: Thanks for the If Then part, it works great.

Silent Ghost Coming Soon
[img=http://img168.imageshack.us/img168/9826/89797ok5.th.gif}

Attachments

Login to view attachments
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 6th Apr 2007 16:46
Check my above post for the if statement.

3.0 Ghtz/1GB DDR400 Ram/Ati 9550 256MB AGP Graphics/100GB Maxtor Sata Drive/Dark Basic Pro 6.5

Know one cares how much you know until they know how much you care.
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 6th Apr 2007 16:48
your welcome.

3.0 Ghtz/1GB DDR400 Ram/Ati 9550 256MB AGP Graphics/100GB Maxtor Sata Drive/Dark Basic Pro 6.5

Know one cares how much you know until they know how much you care.
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 6th Apr 2007 16:52
What version of Dark Basic Classic are you using?
The set cursor statement works great on mine. I have v1.13 enhanced.

3.0 Ghtz/1GB DDR400 Ram/Ati 9550 256MB AGP Graphics/100GB Maxtor Sata Drive/Dark Basic Pro 6.5

Know one cares how much you know until they know how much you care.
Superdean
19
Years of Service
User Offline
Joined: 18th Feb 2006
Location:
Posted: 6th Apr 2007 17:01
it doesn't work for me because i have 2 more lines above the ones I gave that say:
print "Program Ready"
print "press any key to continue"
suspend for key

Silent Ghost Coming Soon
[img=http://img168.imageshack.us/img168/9826/89797ok5.th.gif}
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 6th Apr 2007 17:18
oh,

you would have to drop all the lines down to make room for the ones that print before the ones in the code you posted, then it would work.

3.0 Ghtz/1GB DDR400 Ram/Ati 9550 256MB AGP Graphics/100GB Maxtor Sata Drive/Dark Basic Pro 6.5

Know one cares how much you know until they know how much you care.
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 6th Apr 2007 19:00 Edited at: 6th Apr 2007 19:01
or cls after the input, before printing "you are older than 0"
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 9th Apr 2007 07:45
You would be better having the whole age input enclosed in a Repeat...Until which you can't exit until the correct thing is entered.

If you accept the age entered as a string you are then able to use VAL to convert it into a number - providing a number has been entered correctly. This in effect does the checking for you as letters entered are ignored by VAL if they are at the end of a string and convert to 0 (zero) if at the start.

Input Name Snippet


Input Age Snippet


TDK_Man

Login to post a reply

Server time is: 2025-05-27 18:40:54
Your offset time is: 2025-05-27 18:40:54