COMBINING COMMANDS
	-by David Conner, mailto:lbdavid26@yahoo.com

I wrote this because I added on to Alyce Watson's scripter.bas program and made a command called goeast n.  What it does is goes east a number of pixels, and I am here to show how to combine commands in your programs.  I hope this is clear for you and you can understand it. The program I am using to demonstrate this is a SCRIPTING LANGUAGE.  To learn about these read Issue #98 of the Liberty BASIC Newsletter.

------------------------

First of all, you must have LB 3.01 to run this because it uses the Select Case command. A way to check this is to use the following code:

if val(version$)<3.01 then
	notice "You have To have LB 3.01 to run this program"
	end
End if

[initVariables]
	WindowWidth = 640 : WindowHeight = 480
	UpperLeftX = Int((DisplayWidth - WindowWidth)/2)
	UpperLeftY = Int((DisplayHeight - WindowHeight)/2)
	Dim executeSteps$(20)
	cstep = 0
	tsteps = 0
	crlf$ = chr$(13) + chr$(10) 'carriage return (Cr)/Line Feed (lf)
[addControls]
	nomainwin ' we don't want a mainwindow

	menu #gd, "&File",_
	"&New", [newFile],_
	"&Open", [openFile],_
	"&Save As", [saveAs],_
	"S&ave", [saveFile],|,_
	"&Exit", [quit]

	menu #gd, "Edit" ' place the edit menu here

	menu #gd, "&Help",_
	"&Commands", [commandList],|,_
	"&About", [about]

	button #gd.b1, "Run Script", [runScript],UR,40,10,55,30
	button #gd.b2, "Commands", [commandList],UR,115,10,60,30

	statictext #gd.step, "", 20,10,200,24
	statictext #gd.status, "Draw", 50,10,200,24

	texteditor #gd.te,10,40,300,380 

	graphicbox #gd.g,320,40,300,380

	open "Graphics" for window_nf as #gd

	#gd "trapclose [quit]"
	#gd.te "!font courier_new 12"
	#gd.status "!font arial_black 14"
	#gd.step "!font arial_black 12"
	#gd.g "down; fill black; flush"
	#gd.g "color white; size 3"

	goto [inputLoop]

[about]
	msg$ = "Graphics Demo" + crlf$
	msg$ = msg$ + "A Demo For Combining Commands, 2002"
	notice msg$
	goto [inputLoop]

[commandList]
    cmnd$ = "Command List" + crlf$
    cmnd$ = cmnd$ + "draw n - draws in a striaght line based on a number of pixels" + crlf$
    cmnd$ = cmnd$ + "upmove x y - moves to a specified posistion but doesn't draw" + crlf$
    cmnd$ = cmnd$ + "downmove x y - moves to a specified posistion and draws it" + crlf$
    cmnd$ = cmnd$ + "gonorth n - goes north a specified number of pixels" + crlf$
    cmnd$ = cmnd$ + "goeast n - goes east a specified number of pixels" + crlf$
    cmnd$ = cmnd$ + "gowest n - goes west a specified number of pixels" + crlf$
    cmnd$ = cmnd$ + "gosouth n - goes south a specified number of pixels" + crlf$
    cmnd$ = cmnd$ + "center - put picture in center" + crlf$
    cmnd$ = cmnd$ + "turn d - turn a number of degrees" + crlf$
    cmnd$ = cmnd$ + "down - draw" + crlf$
    cmnd$ = cmnd$ + "up - Don't Draw"
    notice cmnd$

    goto [inputLoop]

[inputLoop]
	wait

[newFile]
	#gd.te "!cls" ' clears the editor
	#gd.g "cls" ' clears the graphicbox
	#gd.g "down; fill black; flush"
	#gd.g "color white; size 3"
	
	goto [inputLoop]

[openFile]
	filedialog "Open a .g file", "*.g", file$ ' opens a filedialog to get a .g file
	open file$ for input as #f ' opens the filename of the result of the filedialog
	#gd.te "!contents #f" ' prints the contents of #f into the editor
	close #f ' closes #f

	goto [inputLoop]

[saveAs]
	filedialog "Save A .G File", "*.g", file$
	if file$ = "" then [inputLoop]	

[saveFile]
	open file$ for output as #f
	#gd.te "!contents? txt$" ' puts the contents of the editor into the variable txt$
	#f txt$ ' prints the contents of the variable txt$ into #f 
	close #f
	
	goto [inputLoop]

[quit]
	close #gd : end
	
[runScript]
	#gd.g "cls; fill black; color white; size 2"
	#gd.g "home; north"
	#gd.te "!lines tsteps" ' gets the number of lines in the editor and stores the info in
	' the variable tsteps
	ReDim executeSteps$(tsteps) ' redimensions the executeSteps$ array to the # of lines in
	' the tsteps variable
	
	for i = 1 to tsteps
	#gd.te "!line "; i; " text$"
	' get current line from i variable and stores it in text$
	if len(text$) = 0 then text$ = "draw 0" ' if text$ is empty command will equal Draw 0
	executeSteps$(i) = text$ ' the variables executeSteps$(i) will equal the text$ variable
	next i

	ok = parse(tsteps)
	
	if ok>0 then
		notice "Error on Line "; ok
		goto [inputLoop]
	end if

	if (tsteps=0) then
		notice "No Code" ' if there is no code in the editor No Code will be displayed
		goto [inputLoop]
	end if

	cursor hourglass ' Change the cursor to hourglass
	#gd.g "down; home; north; fill black; color white" ' start the drawing process
	#gd.g "size 3; flush"
	cstep = 0
	Timer 600, [draw] ' every 600 milliseconds goto [draw]

[draw]
	if (tsteps=0) then Timer 0 ' if there is no code then stop the Timer
	cstep=cstep+1 ' add 1 to each step drawn
	#gd.g " "; executeSteps$(i); " " ' draw the current step
	#gd.te "!origin "; cstep; " 1" ' goto the next line
	#gd.te "!line "; cstep; " txt$" ' get the current line from cstep and store in txt$
	#gd.step txt$ ' print the step into the statictext #gd.step

	t$ = lower$(word$(text$, 1)) ' check to see if draw or not
	if lower$(t$) = "down" then print #gd.status, "Draw!" ' if pen is down then print Draw
	if lower$(t$) = "up" then print #gd.status, "Don't Draw" ' if pen is up then print Don't
	' Draw

	if (cstep>=tsteps) then ' The Drawing is Done
		Timer 0
		cursor normal ' make the cursor normal again
		#gd.g "color palegray; circlefilled 4" ' make a palegray circle
		#gd.g "flush" ' make the picture STICK
		#gd.te "!origin 1 1" ' goto the first line
	end if
	 
	goto [inputLoop]

function parse(num) ' make a function called parse(num)
	Result = 0 ' will return zero unless there is an error
	#gd.status "Compiling" ' print to status COMPILING

	for i = 1 to num 

	s$ = lower$(executeSteps$(i))
	c$ = lower$(word$(executeSteps$(i), 1))

	Select Case c$ ' start making commands 

	case "turn" ' same as lb command
	a = val(word$(s$, 2))
	a$ = str$(a)
	executeSteps$(i) = "turn "; a$

	case "gonorth" ' this has a combined command.  When you determine LB syntax separate the
	'commands with a semicolon ";". With this command gonorth 45 will go north 45 pixels
	b = val(word$(s$, 2))
	b$ = str$(b)
	executeSteps$(i) = "north; go "; b$
	
	case "gosouth" ' this command is also a combined command.
	c = val(word$(s$, 2))
	c$ = str$(c)
	executeSteps$(i) = "north; turn 180; go "; c$

	case "goeast" ' a combined command 
	d = val(word$(s$, 2))
	d$ = str$(d)
	executeSteps$(i) = "north; turn 90; go "; d$ ' here

	case "gowest" ' a combined command
	e = val(word$(s$, 2))
	e$ = str$(e)
	executeSteps$(i) = "north; turn 270; go "; e$	
	
	case "downmove" ' this is a command that is the same as the goto x y command.
	x = val(word$(s$, 2))
	if x<506 then x = 506	
	x$ = str$(x)
	
	y = val(word$(s$, 3))
	if y>506 then y = 506
	y$ = str$(y)
	executeSteps$(i) = "goto "; x$; " "; y$

	case "upmove" ' same as the place x y statement
	f = val(word$(s$, 2))
	if f>506 then f = 506
	f$ = str$(f)

	g = val(word$(s$, 3))
	if g>506 then g = 506
	g$ = str$(g)
	executeSteps$(i) = "place "; f$; " "; g$
	
	case "draw" ' same as the go command
	h = val(word$(s$, 2))
	#gd.g "posxy x y"
	if x+h>506 then h = 506-x
	if y+h>506 then h = 506-y
	h$ = str$(h)
	executeSteps$(i) = "go "; h$

	case "down" ' same as DOWN command
	executeSteps$(i) = "down"
	
	case "up" ' same as UP command
	executeSteps$(i) = "up"
	
	case else ' if there is anything else in the textbox then will goto line which has error
		Result = i
	
		#gd.te "!origin "; i; " 1"
		#gd.te "!select 1 "; i
	exit for
	end select
Next
#gd.status ""
Parse = Result
end function

----------------

All you have to do is combine the commands by a semicolon ";". That's it for my article. Hope you understood.:)		 