Jump to content

DarkBASIC Programming/The Hello World Tradition

From Wikibooks, open books for an open world

Alrighty, you came back. Good, let's hope you have played around with the DarkBASIC editor. Before you find out what the hello world tradition is (older programmers don't spoil it for them!), I think I should tell you something. The DarkBASIC editor is not very windows friendly, so make sure you download an IDE you like and then link it to the DarkBASIC.

So you know: an IDE is an integrated development environment. It allows programming to be easier for professionals and beginners alike. For now, don't worry what an IDE is too much, you're only beginning after all.

Okay, now then time to get to the tradition.


Code


Print "Hello World!"
Print "This is Dbtutor's wikibook on DarkBASIC Programming!!"

End of Code

Copy and paste this source code into the IDE or editor (whichever) and run it. What you get is the easiest program you'll ever write in DarkBASIC. The hello world example is proud tradition of beginning programmers, so let's carry it on. Hello World Program puts the text hello world on the screen. But what are the quotation marks for? The quotation marks are used to show what you want to put on the screen. Otherwise, it would look like one big command.

Your Assignment:

Replace Hello World with any text you want


First of all, I hope you completed the assignment above. In case you haven't, or had problems with this program I'll show you how. Okay, let's say you want to print a couple of things and you need it spaced for readability. Remember I said that print, prints the things inside the quotes? Well they're called strings, now strings are characters that you can change and manipulate. With no string to technically print, you'll just get a blank space. Now for all on one line you use a semi-colon(;). Experiment with these two methods above until you understand them. In DarkBASIC, your program already ends on its own doesn't it?


But, it's good practice if you use the command "end" where your program needs to quit. So after the print commands in hello world, insert the command "end". Now, go to file and build EXE, save the EXE in whatever folder you want and run it. Technically it should just be a flash so quick you cannot see it. That's where you need some sort of waiting system, or input just to let you see the results. So delete the exe and open up DarkBASIC again, in our hello world before the end command insert a wait key. What a wait key does is allow the famous press of any key for the program to end, so rebuild the exe of this program and now run it. As you might see, the program isn't very windows friendly. At the top of the program put in these commands:

Code


Set window on
Set window layout 1,1,1
Set Window title "Hello World - A Friendly Greeting From DarkBASIC"
Set window position 100,200
Set window size 640,480

End of Code

Now run the hello world program, see what happens? We now have a nice little window friendly environment. But hey, if you're on a different computer with different settings you'll miss some of the text, and what on earth are all those numbers for anyways? Okay the numbers are the X coordinates and the Y coordinates in case you didn't do math in school X is horizontal and Y is vertical. In case, you don't know what those words are X runs left and right or across, and Y runs up and down. So X & Y are 2 axes so we have 2 dimensions, when we get to 3d expect to get dimensional for a paragraph or two. Now then for our last part of the day, let's find out how to change the position of where our text goes.

Code


Set cursor 1,50

End of Code



Insert this piece of code above, right above the first Print statement. Our program is long now and we may also forget what some of the things above do. Welcome to comments, the Rem command lets you make notes, anything after Rem is ignored. You should always comment your code, so that others can understand it, and so you can know what you where thinking when you coded it and why you coded it the way you did. Remember, comment heavily!!

So you know: Rem is short for Remark, and if I haven't told you yet BASIC stands for Beginner's All Purpose Symbolic Instruction Code.

Here's what your program should look like in the end, roughly:


Hello World Program Results


Rem Setup the window
Set window on 
Set window layout 1,1,1
Set window title "Hello World Program"
Set window position 100,200
Set window size 640,480

Rem put the first line of text 50 pixels down
Set cursor 1,50
Print "Hello World!"
Print "A friendly greeting from DarkBASIC!"

Rem wait for the press of any key
Wait key
Rem then end
End

End of the Program


Before we go here's a quiz:


In DarkBASIC Strings Start With a:
A)#
B)*
C)'
D)"
And they end with a:
A)%
B)^
C)&
D)"
BASIC stands for:
A)Beginner's All Purpose Symbolic Instruction Code
B)Bears Are Purposely Stealing International Cookies
C)Beginner's Alphanumeric String Informed Code
D)Beginning All Inserted Symbolic Intel Coding
In 2d there are 2 axis which are they:
A)U & V
B)X & Y
C)U & V(in textures), X & Y also
D)Z & U
Rem can make comments for how many lines:
A)1 or More
B)1 or less
C)Single Line
D)Double Line


Okay Here Are the Answers, no cheating!

1 & 2 is obviously D.
3 is A.
4 If you said anything but Z & U you should be on the right track but C is the best answer while
B can be considered the most correct one.
5 is C.

Assignment:

[edit | edit source]

Experiment with the IDE and the DarkBASIC window commands. Comment the hello world program when done. Make a program that contains only comments. Look up IDE on wikipedia. Look around the DarkBASIC website(http://www.thegamecreators.com).