Well, the first thing you should learn about it is all of the variable types, data structures, arrays, then move on to looking at some coding styles. The most important things are the following:
Correct commenting!
There are 3 different ways to make comments in DarkBASIC:
rem This is a comment
// This is a comment
` This is a comment
The keyword
rem is the standard way BASIC does it, you'll see a lot of people on these forums not doing it that way though. You also have the possibility to make longer comments like this:
remstart
So I got this brand new microphone and just had to try out my text-to-speech software.
I hooked everything up and was ready to go in just under a minute.
My friend ripped the microphone from me and ripped ass into it.
The text-to-speech software immediately spat out the word "France".
We were like: "wth?"
remend
Variables!
myVar as integer
myVar as dword
myVar as word
myVar as byte
myVar as boolean
myVar# as float
myVar$ as string
Note that floating point variables always have a
# symbol indicating that they are floats, and string variables always have a
$ symbol indicating that they are strings. You'll see a lot of people (including on these forums) not doing this. It still compiles, but it's not the "standard way" to program in BASIC.
User Defined Types (UDTs)
rem declare our UDT
type myVar_T
Muffins as integer
Heat# as float
Blabla as word
endtype
rem define our variable
myVar as myVar_t
rem now fill our variable with some values
myVar.Muffins = 42
myVar.Heat# = 9000.1
myVar.Blabla = 3
See how the different variables we defined between the
type and
endtype tags can now be used as a sub group of the variable
myVar? This is very useful for keeping your code clean and organized, so try to use as many of these as you can.
You can have UDTs inside UDTs as well:
rem vector 2 UDT
type vec2
x as integer
y as integer
endtype
rem player UDT
type Player_T
Lives as integer
Position as vec2
endtype
rem define our player
Player as Player_T
rem set position of player
Player.Position.x = 30
Player.Position.y = 45
rem set lives of player
Player.Lives = 3
Arrays!
dim myArray(5) as integer
myArray(0) = 5
myArray(1) = 8
myArray(2) = 85
myArray(3) = 8
myArray(4) = 374
myArray(5) = 9
Very useful if you ever want to have more than 1 thing in your game. For example, we could have more than one player (multi player game). In that case it would look like this:
rem vector 2 UDT
type vec2
x as integer
y as integer
endtype
rem player UDT
type Player_T
Lives as integer
Position as vec2
endtype
rem array for players
dim Player(3) as Player_T
rem set position and lives of all of the players
for t = 0 to 3
Player(t).Position.x = 30
Player(t).Position.y = 45
Player(t).Lives = 3
next t
Arrays can also have more than one dimension:
dim myArray(5,5) as integer
UNFORTUNATELY DarkBASIC Pro doesn't support arrays in UDTs, so this here won't compile:
rem this doesn't work. :(
type Player_T
dim Bullet(5)
endtype
Subroutines!
Subroutines help organize your code into groups and let you re-use code. Here's an example:
rem let the user know that we are about to do some crazy magic
print "Prepare for the awesome magic that is a subroutine!"
rem call our subroutine!
gosub _This_Is_A_Subroutine
rem let the user know that the subroutine has successfully returned
print "Subroutine has finished doing it's thang!"
rem wait and end
wait key
end
_This_Is_A_Subroutine:
rem do cool stuff here
print "WOOOAAHA DUDE, we're in a subroutine!"
return
Feel free to copy/paste and run that.
Functions!
Functions are much like subroutines, the only difference is that they can pass values between each other as well. Example:
print "multiplying 5 with 6..."
print Multiply( 5 , 6 )
wait key
end
function Multiply( a , b )
rem multiply the two together
result = a*b
endfunction result
TheComet
"if you don't understand recursion than you probably don't understand recursion." ~Jerico2day