coding is thinking about the instructions you want the computer to perform in a linear fashion. later on as you progress you will learn functions that allow you to group these commands into one word commands with parameters.
lets jump into the DARKBASIC hello world snippet like all other languages to get started.
sync rate 60
sync on
do
print "Hello World"
sync
loop
end
lets break down these commands to understand them
sync rate 60 : sets the rate of refresh in laymans terms to 60 ticks or loops a second.
sync on : activates the sync to be used in your main loop
do : starts the do/loop which will repeat itself forever and ever until you press escape which is the standard key for all programs to stop them in dark basic unless you change that yourself.
print "Hello World" : prints the text Hello World as a string.
A string is a series of characters that the computer has no idea what they are, compared to a variable that might hold a number or a decimal place
sync : this tells the computer language to activate the screen refresh to update what was prior to it, hence in our loop we are printing Hello World again and again.
loop : this completes our loop and tells the computer to go back to the do statement and start all over again.
end : this safely terminates the program after you have completed your instructions.
now lets take this approach a little further into 3d
sync rate 60
sync on
make object cube 1,1
position object 1,0,0,0
position camera 0,5,-5
point camera 0,0,0
do
r = wrapvalue(r+1)
rotate object 1,r,r,r
text 1,1,"Hello World"
sync
loop
delete object 1
end
This program makes a spinning cube in 3d with the text hello world.
lets break it down again.
sync rate 60 : sets the rate of refresh in laymans terms to 60 ticks or loops a second.
sync on : activates the sync to be used in your main loop
make object cube : makes a 3d cube using a media space of 1, each 3d object needs its own media number for the program language to manage it, the extra 1 is for the size of the cube.
position object : this positions the object in 3d space x 0 y 0 z 0
basically the center point in most 3d worlds.
we do the same with the camera but -5 z so backwards in the forwards backwards dimension and up 5 in the y dimension thats up and down.
if you just load an object DB will use an automatic camera viewing feature that should be avoided for simplicity of setting things in your own space and distance.
do : starts the do/loop which will repeat itself forever and ever until you press escape which is the standard key for all programs to stop them in dark basic unless you change that yourself.
in our main loop we declare a variable integer, or a whole number variable called r, rotation for short.
we use another command built by TGC for DB called wrapvalue.
wrapvalue stops the number going past 360, hence 360 degrees of rotation. we add one each time the loop goes around and apply it to the x y and z dimensions of the cube for rotation.
now instead of print we use another similar command called text.
it will print text on the 2d screen on your monitor.
X in 2d is left right, Y is up down.
we set the text to be 1x and 1y and then print the hello world string there each loop cycle.
at the end of our program we safely delete the object we used and end the program.
this is the most basic primer i can imagine for you, covering very basic 2d and 3d.
if that appears to be too much at once, just re read each component and eventually it will all start to make sense.
get a pad and pencil and write down the ideas you want to create a game, then go back and read the commands you need to acheive that.
good luck its a lot of fun once you get the hang of it.