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.

Newcomers DBPro Corner / Input and Variables

Author
Message
Lonnie
21
Years of Service
User Offline
Joined: 28th May 2003
Location:
Posted: 4th Sep 2003 00:18
Whats wrong with this code? Im a newb. I just started a little programming. and i wanted to make a very simple program. But, I cant seem to figure out all the things Im doing wrong... Will some one please give me some pointers on what im doing wrong, and give me a fixxed version of the script? (I think you may beable to tell what im trying to do if you read the code)

Thanks!
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 4th Sep 2003 00:37
take the $ off the years and change the message to "how many years old are you?", then change the output message to "your are about ";milliseconds;" millisecs old", you have tried to store a number in a string, adding $ to the end of a variable makes the number a string, strings are used to hold strings of characters like (for example) years$="the warm summer of sixteen oh two", you can`t do math with strings, on the other hand year=18 works fine, you would need to refine the code to calculate the fraction of the year to get a more exact answer for you example, at the moment to be accurate the user would have to type something like 18.954 in years as his age to get the exact result, cheers.

Mentor.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 4th Sep 2003 00:38
you dont need the WAIT statement as INPUT waits for INPUT....

you need semi-colons in your PRINT statements.....to concatenate
something like
Print "you are "; str$(days); " days old"

Your entire math is off, and the variables your using won't hold what you're asking, especially milliseconds

WAIT at end of program should be WAIT KEY so you can see results, then press any KEY to exit app

-RUST-
Lonnie
21
Years of Service
User Offline
Joined: 28th May 2003
Location:
Posted: 4th Sep 2003 00:42
Right, thanks! Here is the Finish Project:

Print "How old are you?"
INPUT years
days=years*365
Hours=days*24
Minutes=Hours*60
Seconds=Minutes*60
Miliseconds=Seconds*1000
Print "you are " ;days; " days old"
Print "you are " ;Hours; " hours old"
Print "you are " ;Minutes; " minutes old"
Print "you are " ;Seconds; " seconds old"
Print "you are " ;Miliseconds; " miliseconds old!"
Print
Print "Press any key to close"
wait key

But...

When I do Miliseconds for realy high numbers. It end up going negative...
What does that mean?

Thanks for all of your help!
Im sure you will see me often asking questions on these forums.

Later

(oh ya ill change it to "about days(minutes, seconds, ect) # old" Instead of "you are blah blah blah"

thanks!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 4th Sep 2003 01:05
Quote: "When I do Miliseconds for realy high numbers. It end up going negative...
What does that mean?
"


It means the Variable Type you are using cannot hold the value you are trying to give it. In programming, variables have diffent types (memory sizes) so as not to use huge memory areas to hold small values. use integer to hold values of -32768 to +32768, use FLOAT to hold way way larger ones. Read up on variables in Help

-RUST-
Lonnie
21
Years of Service
User Offline
Joined: 28th May 2003
Location:
Posted: 5th Sep 2003 00:03 Edited at: 5th Sep 2003 00:05
I know have a problem with antoher code (Im doing this for school) Im Home schooled so it counts as credits (Im in highschool).
But here is the code.
I need to know what im doin wrong. I cant figure out what im doing wrong with reading if a variable is equel to another one. And then have the computer do something because the variable = what ever.
Thanks!
Here is the code for those of you who dont want to click on the "Source" button lol.

rem My RPG Testing file!
rem / Hp and other charecter things here /
hp=100
atk=10
Mgc=14
Lvl2hp=10
Lvl2atk=2
Lvl2Mgc=2
1#=1
2#=2
3#=3
4#=4








Print
Print
print
print
print
print
print "One day you decide to fly to Canada"
wait 2800
cls
print
print
print
print
print
print
Print "(Why would you go to Canada anyways...)"
wait 2999
cls
print
print
print
print
print
print
print "(Oh well thats how the story goes)"
wait 2400
cls
print
print
print
print
print
print
print "You first day in Canada you decide to go hiking on the wonderful forset trails"
wait 3700
cls
print
print
print
print
print
print
print "But after you eventualy get lost. And come off the trail..."
wait 3500
cls
print
print
print
print
print
print
print "Well you end up finding castle. It appears to be very old to you(but what do you know of old castels?"
wait 4700
cls
print
print
print
print
print
print
print "So you walk up to the door and you"
print "(1) Knock on the door"
print "(2) Open the door and walk right in"
print "(3) You try to bust the door down"
input 1234
if 1234=1 then print "There is no door to knock on. The castle is so old that the door must have rotted out so you just walk in"
if 1234=2 then print "You open the door and walk right in"
if 1234=3 then print "You try to bust the door in. But the door is solid oak. And your not very strong. So you just open the door"
Wait 5000



And im doing this for some practice of RPGs Im very new!

Oh ya if you have any tip at all. I could sure use em! Thanks!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Sep 2003 01:12 Edited at: 5th Sep 2003 01:17
you could save some typing by using SET CURSOR x,y before your PRINT statements to place the text on the screen where you want it, instead of typing print over and over.

also I would not use numbers as viarable names - it will get you headaches sooner or later. Try hungarian notation instead...

example for naming a string variable use "str" and then something that lets you know what the variable holds like strFirstName or strPlayerName... for integers you could use intScore or intHits or from your thing above intChoice...

hope this helps

-RUST-
Lonnie
21
Years of Service
User Offline
Joined: 28th May 2003
Location:
Posted: 5th Sep 2003 01:17
Thanks Rustler! Your realy helped me out! But Im still having trouble on the code. Its this part:

if 1234=1 then print "There is no door to knock on. The castle is so old that the door must have rotted out so you just walk in"

Thanks!

Do Print "Hello World"
Wait 2003 loop
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Sep 2003 01:19
try input 1234$
if 1234$=1......................................
etc



-RUST-
Lonnie
21
Years of Service
User Offline
Joined: 28th May 2003
Location:
Posted: 5th Sep 2003 01:21
K cool

Thanks!

Do Print "Hello World"
Wait 2003 loop
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Sep 2003 01:53
did you see my bit about hungarian notation a few posts above, I was editing it when you read the first version - go back up a few and have a look

and your welcome

-RUST-
Lonnie
21
Years of Service
User Offline
Joined: 28th May 2003
Location:
Posted: 5th Sep 2003 20:49
Ok, I know have another question. What would be a better way for me to store the enemy Data and your data? Would I be able to do it through Arrays?

Thanks!

Do Print "Hello World"
Wait 2003 loop
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Sep 2003 21:08 Edited at: 5th Sep 2003 21:14
You could use TYPES.
Look in the help for TYPES (User Defined Types)

You could make one called ENEMY

TYPE ENEMY
intHitsRemaining as integer
strName as String
etc etc
End Type

Then instantiate a type for your enemy/ies

Enemy1 as Enemy
Enemy2 as Enemy

Enemy1.intHitsRemaining=20
Enemy1.strName="Neil"
Enemy2.intHitsRemaining=15
Enemy1.strName="Bob"


My syntax may be a little off but you get the idea. check the help. Types are a great way of sectioning-off your data/variable in neat packages. Use a type to store a player's data as well.

EDIT: you can use arrays of types so if your game has ten enemies you could make an array of enemy objects from the original definition.

I think its DIM ENEMY(9) as Enemy (Someone dblcheck me on this)
This creates enemies 0 thru 9, each a carbon copy of the original enemy type (we're approaching CLASSES here too bad none in dbp)Anyway read up on types and arrays

-RUST-
ChipOne
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Canada
Posted: 5th Sep 2003 23:35
instead of the print commands, you can shorten your code immensely like this (btw, i corrected some of your text for you):

text 15, 300, "One day you decide to fly to the greatest country ever of Canada"
wait 2800
cls

text 15, 300, "(Why wouldn't you go to Canada anyways...)"
wait 2999
cls

text 15, 300, "(Oh well thats how the story goes)"
wait 2400
cls

etc.


when YOU have a choice to make based on an input from the user where there is a limited number of choices, SELECT statements are great. everything from your input statement forward would be replaced with this:

`------
SELECT int(input$())
CASE 1: txt$ = "First Message": ENDCASE
CASE 2: txt$ = "Second Message": ENDCASE
CASE 3: txt$ = "Third Message": ENDCASE
CASE 4: txt$ = "Etc. Message": ENDCASE
CASE DEFAULT: txt$ = "You didn't pick a valid choice.": ENDCASE
ENDSELECT

CLS
TEXT 10, 300, txt$
`------

SELECT statements are used to make choices based on the value of a variable, with the added advantage that you can setup a 'catch-all' case (CASE DEFAULT) that is used if you don't get what you're looking for or expecting from the user.

in this case, we're putting the input$() in the SELECT statement and casting it to an integer (changing the value from a string to a number).

onto types. woof.

types are a great way of storing related information in one place. rust's example is a good one. think of a type as a custom definition of a variable, but the variable is able to hold multiple values and multiple types. cool, eh? so, you can store a name (string), the level (integer), the hit points (integer) and the effectiveness of spells as a percentage (float) all in the same place.

the first thing you do is create an 'instance' of your type. using rust's example from above, you are creating an 'instance' of an ENEMY.

BigBossBaddie as ENEMY

Now, BigBossBaddie has a bunch of empty 'fields' that you fill in, such as name, hit points, etc.

sheesh...that's a lot for now. get your head around that and we'll start talking arrays. those are good for your story text, enemy information, and about a billion other things (in fact, if you can name something that an array isn't good for i'll give you a canadian penny when you come to visit me).

cheers.

-= i only do what my rice krispies tell me to do =-
Lonnie
21
Years of Service
User Offline
Joined: 28th May 2003
Location:
Posted: 6th Sep 2003 00:08 Edited at: 6th Sep 2003 00:10
Lol. Thanks ChipOne and Rustler! You helped alot! Im going to make a RPG. And Im sorry about the Canada thing. But I actualy like the way you "perfected" the text. Mabey Ill change it to.. One day you decide to goto Madadascar for no apparent reason... lol

Oh well I was just tring to think of something. Thanks alot both of ya! Im sure you will see me post much more(and ask many more questions) as the school year progresses.

Thanks!
Later

Oh and uhh... I am going to Canada next year (or atleast I think i am, to see a my grandpas brother) So mabey Ill take you up on your deal. lol j/k (I am going to Canada though!!!)

Do Print "Hello World"
Wait 2003 loop
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 6th Sep 2003 00:53
no problem
glad to help

-RUST-

Login to post a reply

Server time is: 2024-09-20 21:28:59
Your offset time is: 2024-09-20 21:28:59