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 / Basic things - im a fresh newbie

Author
Message
amt222
18
Years of Service
User Offline
Joined: 12th May 2006
Location: Earth
Posted: 12th May 2006 22:07
This may sound dumb, but how can I get DBP to 'print' a word when i press F1, or any other key? (F1 preferred). I am using the IF and THEN function. I am still just working out how stuff works and experimenting...

By the way, before you might start flaming me that i didn't look for a thread or post or tutorial, its either because i couldn't find one, or i just can't find stuff...

Thanks

amt
The Nerd
20
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Denmark
Posted: 12th May 2006 22:21 Edited at: 12th May 2006 22:22


That code will show the message "Hello World!" when you press F1.

-The Nerd

3D Arcade-like game:
SpaceBattle-Shootout
amt222
18
Years of Service
User Offline
Joined: 12th May 2006
Location: Earth
Posted: 12th May 2006 22:38
thanks... i didn't know it would be that complicated...

amt
amt222
18
Years of Service
User Offline
Joined: 12th May 2006
Location: Earth
Posted: 12th May 2006 22:54
Oh yeah...

i did this, trying to delete just the "Hello World" when you depress F1.



didnt work.

And whats the "loop" for?

Any ideas?

amt
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 12th May 2006 23:21
The "loop" is the thing that ends the "do".

Basically, the program will keep looping over and over again. Your code doesn't work because CLS doesn't require an argument - it clears the whole screen.

I think the code you are looking to do is more like:

This code will print "Hello World" to the top left of the screen while you hold down F1, but will disappear if you let go. Hope this helps!
Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 12th May 2006 23:53
Here's the thing, a do/loop (everything in between those two words) means that every frame, the program will do everything between those two words.

That means that if you have:

Then every single frame, (tiny bit of program time) it will do the bit between the do/loop. In this case, it will print "Hello" on the next line. This isn't good, in our case as it'll spam off the bottom of the page in a big line.

You need to learn about three things:
cls - cls on its own, or with a colour (like "cls rgb(255,0,0)") will clean the screen of everything to one colour. By default that is black, but in the colour example, it would be red. (255 in the red channel, and 0 in green and blue).
set cursor 0,0 - this will put your 'print' cursor somewhere on the screen - in this example at X=0 and Y=0, which is the very top left of the screen. Using this in our do/loop would stop the Prints from scrolling off the bottom of the screen.
variables - not a command, but a very important part of programming. What you want to do is store the state of your printing. I.e. if you had pressed F1 once, you want to print stuff, and if you press it again, you want to stop printing stuff. That's a state (print or not) - we could use '1' as 'we want to print' and '0' as 'no print'. We put this in a variable - just a name that we keep numbers in.

So, enough theory - here's a bit of code that should demonstrate this in action:

Hope that helps.
amt222
18
Years of Service
User Offline
Joined: 12th May 2006
Location: Earth
Posted: 13th May 2006 00:24
when you type set cursor 0,0, what is the numbers for the center? both width and height? i cant work out the right numbers...

As for the code thing, when you do this:
you cant keep the "F1 to print Hello World!"

Is there a way to keep the "F1... World!" on screen while pressing F1 makes "Hello World" and depressing it deletes it while keeping "F1... World!"?

(if you dont understand something just post... )

amt
amt222
18
Years of Service
User Offline
Joined: 12th May 2006
Location: Earth
Posted: 13th May 2006 00:36
Another question: I did this:

to try to move the box up and down... didnt work...

what do i have to do?

amt
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 13th May 2006 03:41
Quote: "By the way, before you might start flaming me that i didn't look for a thread or post or tutorial, its either because i couldn't find one, or i just can't find stuff..."


Don't worry - I'm not going to start flaming you...

I'm just going to say that your very basic questions show that you need to go away and do a bit of reading so you get an understanding of the elementary stuff - like "what loops are".

A good start would be the help files which came with the version of DB you are using. Press F1 and read all of the commands.

It doesn't matter if you understand them or not - you'll just have a better chance of remembering them later on when you understand things a little more.

Apart from that, things like loops are quite adequately explained in the help files - along with a shedload of other things.

As for a tutorial for real beginners to programming, click on the link at the bottom of my post for some reasonable 'intro to programming' tutorials.

And good luck!

And by the way, in your last example, the box doesn't move because box1# is a variable and nowhere do you tell DB to apply that variable to the box's position.

Once again, my tutorials will explain what variables are.

TDK_Man

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 13th May 2006 06:18
adding on to what TDK said, another resource for learning DB is to buy the book called "Beginners Guide to DarkBASIC Game Programming" (approx 700 pgs). They should have a link to it on the main page, but I am not sure. As much as it stinks that you have to buy it to learn the language faster, but it was probably one of the wisest choices in my life to get it, as far as programming is concerned.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th May 2006 13:13
Quote: "Is there a way to keep the "F1... World!" on screen while pressing F1 makes "Hello World" and depressing it deletes it while keeping "F1... World!"?"


You see, that question makes me wonder if you are cut out for programming. You have nearly every element of the program made for you, and all you have to do is print the line again, but you couldn't figure out how to do it. Without being able to fix that problem, how are you ever going to fix a problem with a game?

smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 13th May 2006 16:27
change this

to


and change this


to


life's one big game
spec= 2ghz, 1gb ram, 512mb gpu, directx 9.0c, dbpro and classic
amt222
18
Years of Service
User Offline
Joined: 12th May 2006
Location: Earth
Posted: 13th May 2006 19:55
thanks for you help, you see... the thing is that im in my teens still
The code
didnt get the box to move, but i found out that changing the code to this
makes the box move, although it instantly jumps back to its original position, when i depress up or down key...

amt
Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 13th May 2006 22:34
I really do recommend you read TDK's tutorials - they were written to help complete beginners like yourself - no matter their ages.

As for your box moving problem, the thing is you're putting the Y position into box1#. You then add or subtract 5 from that number.

Then, you position it in the world:

position object objectnum, X, Y, Z

You've put box1# into the Z component of the position - not the Y position (which is what you've read in and put in box1#).

You'll find if you change your position object command to use box1# in the Y position, instead of the Z, then the object will ZIP off the screen really quickly. But, it will be doing what you want.

As for the printing problem earlier, you want to look into 'debouncing' a key and storing the state of the printing. Really, read TDK's stuff - I don't want to attempt to repeat what he's already written up wonderfully.
amt222
18
Years of Service
User Offline
Joined: 12th May 2006
Location: Earth
Posted: 14th May 2006 12:22
Thanks Tinker, i will read TDK's tutorials



amt

Login to post a reply

Server time is: 2024-11-26 21:38:18
Your offset time is: 2024-11-26 21:38:18