I made this tutorial for someone at C4D cafe, to show how you could use variables in a usable code. I think his name on here is Implosive.
Well here is your tutorial dudes, read the notes as they explain things
`Menu making tutorial using variables
`For beginners
`by Seppuku Arts
`First off, lets use the clear screen command, solves the flickering screen problems on some
`chipsets
cls
`This is the syncronisation command
sync on
`Set the speed of syncronisation, as this is a menu, you don't want it too fast
sync rate 10
`This is going to be a text menu tutorial and not button, so we'll need to play
`with text settings
`First of all, lets pick a font, remember when using strings(text) and file name, remember
`to use speech marks
set text font "courier new"
`Next, we need a size for the font, pretty basic, the size are equivalent to those
`in Microsoft word, but remember they will seem differant sizes at differant resolutions
set text size 30
`We'll ignore the bold, italic settings for now as they are irrelevant, but the commands
`are found in the help file of dark basic professional
`Colours are important too, so use the ink command, the first variable is the text colour
`and the second is the background, for ease, you can set it using RGB
ink rgb(255,255,255),rgb(0,0,0)
`the text should be white and the background should be black, if you are unsure on what colour
`you want, use windows Paint to help you with the RGB commands
`as we are using variables, we will need to set a variable for the menu
m# = 0
`The # identifier makes a numeric variable a float.
` Leave it off and it's an integer - but still a number variable.
`m is the variable (edited because I made a mistake, sorted thanks to
`TDK)
`some variables can be text, and we would use '$' for that, but it is not part of this
`tutorial
`lets start a loop
do
`lets give the variable a job when at 0, we can do this with an 'if'
`m# = 0 is the new game part of the code
if m# = 0
`clear the screen
cls
`we want the menu text to show, so lets use text commands
`if you look at new game you will notice it looks like '-new game-' I am using those changes
`in text to make the code easy and signify what is selected.
center text 100,40,"-New Game-"
center text 100,70,"Load Game"
center text 100,100,"Quit"
`when making an extended 'if' command, you need to tell the code its ended
endif
`lets repeat the same principle at differant variables for differant menu items
`m# = 1 is the Load Game part of the code
if m# = 1
cls
center text 100,40,"New Game"
`notice the change in '-'
center text 100,70,"-Load Game-"
center text 100,100,"Quit"
endif
`Finally, the 'quit' part of the menu
if m# = 2
cls
center text 100,40,"New Game"
center text 100,70,"Load Game"
center text 100,100,"-Quit-"
endif
`as this is the quit command, you want to be able to press enter and quit the program, this
`is easy to do
if m# = 2 and returnkey()=1 then end
`We've got the variables sorted out, but we can't scroll through them, you want to be able to
`use the cursor keys to do this
`So I'm going to make the cursor keys increase and decrease the variables
`up will decrease, down will increase
if upkey()=1 then dec m#,1
if downkey()=1 then inc m#,1
`here you will find the problem if the variable goes higher than 2, nothing happens, same for
`below 0, lets solve this by making it if the variable is higher the 2 it will become 0
`and if below 0 it will equal 2.
if m# > 2 then m# = 0
if m# < 0 then m# = 2
`finally, when you use this, you will want the newgame variable to go to new game
`when you press enter, you will need to learn how to use labels, I will use an example of a
`label you could use which would be 'newgame:' so now you would be able to link to the part
`of the code where that label is located, which would be the start of the game
`the code linking from the menu to this label would be (I'll use it as a comment, other wise
`the code won't work with it in)
`if m# = 0 and returnkey()=1 then goto newgame
`lets refresh the syncronisation
sync
`use this to tell the code its got to loop back to the start of the loop
loop
[edit]
Forgot to mention this is directed at Dark Basic Professional, but I don't see why it wouldn't work in Dark Basic Classic