home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 245
/
245.d81
/
t.tutorial2
< prev
next >
Wrap
Text File
|
2022-08-26
|
14KB
|
649 lines
u
DotBASIC Tutorial
Part 2
by Dave Moorman
Now it is time to go back to
B.QUIZ and write the Event Handling
Routine. When you run B.QUIZ and get
to your main screen, you can stop by
clicking Exit.
1000 qn=0
1001 qt=0
1002 sc=0
These variables will keep track of
the scores. QN is Question Number (how
many questions have been asked). QT is
for Questions answered correctly. SC
is for accumulating the scores given
by the quiz.
1003 .ss,208
.SS,Page -- Screen Stash the screen
image and its color to memory,
beginning at the given Page number.
Pages 208 and 216 are perfect for
this task.
1004 .b$,"$:q.*",dv,40960,127
.B$,"$:string",drive,location,#of
filenames -- This command Bloads
Directory. The "$:string" is just like
what you would use with
LOAD"$:wild*",8.
DotBASIC already has set the variable
DV to the current drive number. You
have to put the directory data
somewhere; we are using the space
under BASIC ROM, 40960 to 45056.
Four Kilobytes has room for as many as
127 file names (at 32 characters for
each directory line).
1006 .rk,40960
.RK,location -- Rack data, beginning
at given location. Rack turns an
Edstar file or loaded directory into
a virtual string array. The number of
items is put in N%.
1007 if n%=0 then:.er:return
So, if N%=0 then there was nothing in
the file (no quiz files on the disk,
in this case).
.ER -- Event screen Restore put the
original screen back.
RETURN -- Returns to the Event Driven
loop at line 100.
Otherwise...
1008 .$l,45056
.$L,location -- String Link at
location. This sets up the ability to
store strings in memory in a format
that can be Racked. We are using
space under BASIC ROM beginning at
page 176 -- 45056 to 49151.
1010 for x=1 to n%
1012 .ri,x
1014 .$p,mid$(f$,3)
1016 next
Now, we go through the Racked
data, using the FOR-NEXT loop to index
.RI,index -- Rack Index. The string
is placed in W$. If this is a
directory (as it is in this case),
the filenames are placed in F$.
.$P,string -- String Put puts the
string in memory, beginning at the
location set by .$L,location. The
result is just like data bloaded from
an Edstar file. In this case, we are
scrubbing off the "P." prefix on each
filename.
1018 .rk,45056
And we Rack the strings we just put
in memory.
1020 .az,1
.AZ,position -- Alphabetize Racked
data, beginning with given string
position.
1021 .ml,12,27,5,22,6,14,1,1,0,"",""
.ML,X1,X2,Y1,Y2,BX,IC,U,H,LOC,T$,B%
-- Here is one of the most powerful
and useful Objects available on
DotBASIC -- Scrolling Menu. You give
the four coordinates to place it on
the screen, then the colors you want
for the BoX, ICons, Unhighlighted
items, and Highlighted items. The
next parameter is LOCation of the
data -- if the data has not already
been Racked. In this case, we use 0,
so we do not lose the alphabetization.
T$ and B$ can be used to put text at
the top and/or bottom of the menu. The
user's selection will be in W$
1022 if w$="" then:.er:return
So, if W$ is empty, we return to
the Event Driven Loop at line 100.
Otherwise...
1023 .sr,208
.SR,Page -- Screen Restore -- puts
the screen image and color tucked
away at Page by .SS,Page back on the
screen. Great way to get rid of
dialog boxes and menus.
1024 .b0,"q." + w$,dv,40960
.B0,filename$,drive,location --
Bloads the file, as places a zero
byte at the end. The zero byte is
required by the Rack command (in
order to find the end of the data).
1026 .rk,40960
And here we Rack the file.
Remember, this is the quiz file you
created with Edstar or Mr. Edstar.
1028 o=1
We will use the variable O as
OFFSET, pointing to the beginning of
each question in the quiz.
1029 .ri,o
1030 .tx,7+128
1032 .p@,22,0,w$
So, we find the first line (0=1)
of the data.
.TX,color+rev -- This sets the color
of the text to be printed (like
POKE646,color). Add 128 to turn on
Reverse.
.P@,X,Y,string -- Print At screen
coordinates X,Y. Only prints strings.
Now we have the quiz loaded and
the title (the first line of the data)
displayed. We are ready to put the
quiz data on the screen.
1100 .ri,o+1
1101 ifleft$(w$,8)="end quiz"then7100
The first thing we need to do is
check to see if this is the end of the
quiz, marked in the data with the
words "end quiz". If it is, we will go
to line 7100. (We will get to 7100
later. If you like, add
7100 .of:stop
to your program for now.)
1102 .tx,3+128
Set the text color to Cyan
Reversed
1104 for x=1to17
1106 .ri,x+o
1108 a$(x)=w$
1110 next
Each quiz question has 17 lines.
For simplicity, we put them in an
array. Of course, if we are going to
use an array with more than 10 or 11
items, we have to DIM it:
13 dim a$(20)
1120 for x=1to5
1121 .bx,0,38,x+1,x+1,160,3
1122 .pc,x+1,a$(x)
1124 next
With this, we put the question
portion on the screen.
.BX,X1,X2,Y1,Y2,SC,CO -- draws a box
on the screen between coordinates
X1,X2,Y1,Y2, using Screen Code SC, in
color CO. Here we use Screen Code 160
(reversed space) and color 3 (Cyan).
1125 z=1
1126 for x=6to15 step3
We are dividing up the rest of the
data into the four answers
1128 a(z)=val(a$(x))
A(Z) holds the score value for
each answer.
1129 z=z+1
Z is the answer number.
1130 for y=1to2
1131 .bx,0,38,x+y+z+1,x+y+z+1,160,3
1132 .pc,x+y+z+1,a$(x+y)
1134 next
Then we draw a box over each line
of each answer (a good way to wipe out
what was there before).
.PC,Y,string -- Print Center on row Y.
Finding out how to get the answers
to print into the boxes on the screen
was a matter of trial and error.
Hence, the X+Y+Z+1. Not elegant, but
it works (at least for the way I
created my main screen with VDOT.)
1135 next
And then the next Answer.
POINT AND CLICK
Back when we were designing the
screen, we mentioned that Event Driven
code does not work so well for
everything. So we will have to create
our own point-and-click controls. This
is not really that hard, thanks to the
powerful commands of DotBASIC.
1200 pokemv+1,35
The first step is to set up a
different place in memory for the
Regions we will use in this section.
POKE MV+1,35 works just fine.
1201 .rd,1,0,38,10,11
1202 .rd,2,0,38,14,15
1203 .rd,3,0,38,18,19
1204 .rd,4,0,38,22,23
1205 .rd,5,8,13,0,0:
.RD,#,X1,X2,Y1,Y2 -- Region Define,
given the region number (#) and the
screen coordinates. You can check
each defined region with .RA,#,160,7.
This will draw a yellow box in the
region so numbered (#). In this case,
regions 1-4 are answer boxes, while
region 5 is the Exit command.
1206 .bx,0,38,0,0,255,7
This BoX simply makes the menu bar
at the top of the screen nice and
yellow.
1300 .do
1310 .ma
1340 .un cr%
1341 ?cr%:.of:stop
Ah hah! A DO-LOOP! These are so
easy to write, you hardly need Event
Driven technology at all.
Try it out. The backgrounds do not
change with rollovers, and hotkeys are
not enabled yet, but if you click on
an answer box, you stop the program
and print the variable CR%. It will
hold the Clicked Region.
.DO starts the DO-LOOP
.MA is Mouse Ask -- which brings all
the information about the current
mouse state into DotBASIC. Of all the
stuff .MA can tell us, all we need
right now is CR% -- was there a click
over a region? (The regions defined in
1200-1205)
.UN CR% -- and we keep looping until
there is a click over a region. When
CR% is Not Zero, the program falls
through -- and we will handle the
click.
But first, we want to have the
colors of the regions change with
roll-overs. To complicate things, we
need regions 1 - 4 change from cyan to
light green, and region 5 change from
yellow to orange.
This sounds like a job for an
array -- and an array we set up at the
beginning of the program. Lets put it
at line number 4000, then we can GOSUB
to it at the top of the program.
4000 dim c(1,5)
4001 for x=1to4
4002 c(0,x)=3:c(1,x)=13
4003 next
4004 c(0,5)=7:c(1,5)=8
4005 return
Actually, this is VERY straight-
forward BASIC. We need each region to
switch between color 0 to color 1. For
the first 4, we use the FOR-NEXT loop
the do the assignments. C(0,x) is the
unhighlighted color. C(1,x) is the
hightl