home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 245 / 245.d81 / t.tutorial2 < prev    next >
Text File  |  2022-08-26  |  14KB  |  649 lines

  1. u
  2.           DotBASIC Tutorial
  3.                 Part 2
  4.            by Dave Moorman
  5.  
  6.  
  7.     Now it is time to go back to
  8. B.QUIZ and write the Event Handling
  9. Routine. When you run B.QUIZ and get
  10. to your main screen, you can stop by
  11. clicking Exit.
  12.  
  13. 1000 qn=0
  14.  
  15. 1001 qt=0
  16.  
  17. 1002 sc=0
  18.  
  19.     These variables will keep track of
  20. the scores. QN is Question Number (how
  21. many questions have been asked). QT is
  22. for Questions answered correctly. SC
  23. is for accumulating the scores given
  24. by the quiz.
  25.  
  26. 1003 .ss,208
  27.  
  28. .SS,Page -- Screen Stash the screen
  29. image and its color to memory,
  30. beginning at the given Page number.
  31. Pages 208 and 216 are perfect for
  32. this task.
  33.  
  34. 1004 .b$,"$:q.*",dv,40960,127
  35.  
  36. .B$,"$:string",drive,location,#of
  37. filenames -- This command Bloads
  38. Directory. The "$:string" is just like
  39. what you would use with
  40.  
  41.            LOAD"$:wild*",8.
  42.  
  43. DotBASIC already has set the variable
  44. DV to the current drive number. You
  45. have to put the directory data
  46. somewhere; we are using the space
  47. under BASIC ROM, 40960 to 45056.
  48. Four Kilobytes has room for as many as
  49. 127 file names (at 32 characters for
  50. each directory line).
  51.  
  52. 1006 .rk,40960
  53.  
  54. .RK,location -- Rack data, beginning
  55. at given location. Rack turns an
  56. Edstar file or loaded directory into
  57. a virtual string array. The number of
  58. items is put in N%.
  59.  
  60. 1007 if n%=0 then:.er:return
  61.  
  62. So, if N%=0 then there was nothing in
  63. the file (no quiz files on the disk,
  64. in this case).
  65.  
  66. .ER -- Event screen Restore put the
  67. original screen back.
  68.  
  69. RETURN -- Returns to the Event Driven
  70. loop at line 100.
  71.  
  72.     Otherwise...
  73.  
  74. 1008 .$l,45056
  75.  
  76. .$L,location -- String Link at
  77. location. This sets up the ability to
  78. store strings in memory in a format
  79. that can be Racked. We are using
  80. space under BASIC ROM beginning at
  81. page 176 -- 45056 to 49151.
  82.  
  83. 1010 for x=1 to n%
  84.  
  85. 1012 .ri,x
  86.  
  87. 1014 .$p,mid$(f$,3)
  88.  
  89. 1016 next
  90.  
  91.     Now, we go through the Racked
  92. data, using the FOR-NEXT loop to index
  93.  
  94. .RI,index -- Rack Index. The string
  95. is placed in W$. If this is a
  96. directory (as it is in this case),
  97. the filenames are placed in F$.
  98.  
  99. .$P,string -- String Put puts the
  100. string in memory, beginning at the
  101. location set by .$L,location. The
  102. result is just like data bloaded from
  103. an Edstar file. In this case, we are
  104. scrubbing off the "P." prefix on each
  105. filename.
  106.  
  107. 1018 .rk,45056
  108.  
  109. And we Rack the strings we just put
  110. in memory.
  111.  
  112. 1020 .az,1
  113.  
  114. .AZ,position -- Alphabetize Racked
  115. data, beginning with given string
  116. position.
  117.  
  118. 1021 .ml,12,27,5,22,6,14,1,1,0,"",""
  119.  
  120. .ML,X1,X2,Y1,Y2,BX,IC,U,H,LOC,T$,B%
  121. -- Here is one of the most powerful
  122. and useful Objects available on
  123. DotBASIC -- Scrolling Menu. You give
  124. the four coordinates to place it on
  125. the screen, then the colors you want
  126. for the BoX, ICons, Unhighlighted
  127. items, and Highlighted items. The
  128. next parameter is LOCation of the
  129. data -- if the data has not already
  130. been Racked. In this case, we use 0,
  131. so we do not lose the alphabetization.
  132. T$ and B$ can be used to put text at
  133. the top and/or bottom of the menu. The
  134. user's selection will be in W$
  135.  
  136. 1022 if w$="" then:.er:return
  137.  
  138.     So, if W$ is empty, we return to
  139. the Event Driven Loop at line 100.
  140. Otherwise...
  141.  
  142. 1023 .sr,208
  143.  
  144. .SR,Page -- Screen Restore -- puts
  145. the screen image and color tucked
  146. away at Page by .SS,Page back on the
  147. screen. Great way to get rid of
  148. dialog boxes and menus.
  149.  
  150. 1024 .b0,"q." + w$,dv,40960
  151.  
  152. .B0,filename$,drive,location --
  153. Bloads the file, as places a zero
  154. byte at the end. The zero byte is
  155. required by the Rack command (in
  156. order to find the end of the data).
  157.  
  158. 1026 .rk,40960
  159.  
  160.     And here we Rack the file.
  161. Remember, this is the quiz file you
  162. created with Edstar or Mr. Edstar.
  163.  
  164. 1028 o=1
  165.  
  166.     We will use the variable O as
  167. OFFSET, pointing to the beginning of
  168. each question in the quiz.
  169.  
  170. 1029 .ri,o
  171.  
  172. 1030 .tx,7+128
  173.  
  174. 1032 .p@,22,0,w$
  175.  
  176.     So, we find the first line (0=1)
  177. of the data.
  178.  
  179. .TX,color+rev -- This sets the color
  180. of the text to be printed (like
  181. POKE646,color). Add 128 to turn on
  182. Reverse.
  183.  
  184. .P@,X,Y,string -- Print At screen
  185. coordinates X,Y. Only prints strings.
  186.  
  187.     Now we have the quiz loaded and
  188. the title (the first line of the data)
  189. displayed. We are ready to put the
  190. quiz data on the screen.
  191.  
  192. 1100 .ri,o+1
  193.  
  194. 1101 ifleft$(w$,8)="end quiz"then7100
  195.  
  196.     The first thing we need to do is
  197. check to see if this is the end of the
  198. quiz, marked in the data with the
  199. words "end quiz". If it is, we will go
  200. to line 7100. (We will get to 7100
  201. later. If you like, add
  202.  
  203. 7100 .of:stop
  204.  
  205. to your program for now.)
  206.  
  207.  
  208. 1102 .tx,3+128
  209.  
  210.     Set the text color to Cyan
  211. Reversed
  212.  
  213. 1104 for x=1to17
  214.  
  215. 1106 .ri,x+o
  216.  
  217. 1108 a$(x)=w$
  218.  
  219. 1110 next
  220.  
  221.     Each quiz question has 17 lines.
  222. For simplicity, we put them in an
  223. array. Of course, if we are going to
  224. use an array with more than 10 or 11
  225. items, we have to DIM it:
  226.  
  227. 13 dim a$(20)
  228.  
  229. 1120 for x=1to5
  230.  
  231. 1121 .bx,0,38,x+1,x+1,160,3
  232.  
  233. 1122 .pc,x+1,a$(x)
  234.  
  235. 1124 next
  236.  
  237.     With this, we put the question
  238. portion on the screen.
  239.  
  240. .BX,X1,X2,Y1,Y2,SC,CO -- draws a box
  241. on the screen between coordinates
  242. X1,X2,Y1,Y2, using Screen Code SC, in
  243. color CO. Here we use Screen Code 160
  244. (reversed space) and color 3 (Cyan).
  245.  
  246. 1125 z=1
  247.  
  248. 1126 for x=6to15 step3
  249.  
  250.     We are dividing up the rest of the
  251. data into the four answers
  252.  
  253. 1128 a(z)=val(a$(x))
  254.  
  255.     A(Z) holds the score value for
  256. each answer.
  257.  
  258. 1129 z=z+1
  259.  
  260.     Z is the answer number.
  261.  
  262. 1130 for y=1to2
  263.  
  264. 1131 .bx,0,38,x+y+z+1,x+y+z+1,160,3
  265.  
  266. 1132 .pc,x+y+z+1,a$(x+y)
  267.  
  268. 1134 next
  269.  
  270.     Then we draw a box over each line
  271. of each answer (a good way to wipe out
  272. what was there before).
  273.  
  274. .PC,Y,string -- Print Center on row Y.
  275.  
  276.     Finding out how to get the answers
  277. to print into the boxes on the screen
  278. was a matter of trial and error.
  279. Hence, the X+Y+Z+1. Not elegant, but
  280. it works (at least for the way I
  281. created my main screen with VDOT.)
  282.  
  283. 1135 next
  284.  
  285.     And then the next Answer.
  286.  
  287.  
  288. POINT AND CLICK
  289.  
  290.     Back when we were designing the
  291. screen, we mentioned that Event Driven
  292. code does not work so well for
  293. everything. So we will have to create
  294. our own point-and-click controls. This
  295. is not really that hard, thanks to the
  296. powerful commands of DotBASIC.
  297.  
  298. 1200 pokemv+1,35
  299.  
  300.     The first step is to set up a
  301. different place in memory for the
  302. Regions we will use in this section.
  303. POKE MV+1,35 works just fine.
  304.  
  305. 1201 .rd,1,0,38,10,11
  306.  
  307. 1202 .rd,2,0,38,14,15
  308.  
  309. 1203 .rd,3,0,38,18,19
  310.  
  311. 1204 .rd,4,0,38,22,23
  312.  
  313. 1205 .rd,5,8,13,0,0:
  314.  
  315. .RD,#,X1,X2,Y1,Y2 -- Region Define,
  316. given the region number (#) and the
  317. screen coordinates. You can check
  318. each defined region with .RA,#,160,7.
  319. This will draw a yellow box in the
  320. region so numbered (#). In this case,
  321. regions 1-4 are answer boxes, while
  322. region 5 is the Exit command.
  323.  
  324. 1206 .bx,0,38,0,0,255,7
  325.  
  326.     This BoX simply makes the menu bar
  327. at the top of the screen nice and
  328. yellow.
  329.  
  330. 1300 .do
  331.  
  332. 1310 .ma
  333.  
  334. 1340 .un cr%
  335.  
  336. 1341 ?cr%:.of:stop
  337.  
  338.     Ah hah! A DO-LOOP! These are so
  339. easy to write, you hardly need Event
  340. Driven technology at all.
  341.  
  342.     Try it out. The backgrounds do not
  343. change with rollovers, and hotkeys are
  344. not enabled yet, but if you click on
  345. an answer box, you stop the program
  346. and print the variable CR%. It will
  347. hold the Clicked Region.
  348.  
  349. .DO starts the DO-LOOP
  350.  
  351. .MA is Mouse Ask -- which brings all
  352. the information about the current
  353. mouse state into DotBASIC. Of all the
  354. stuff .MA can tell us, all we need
  355. right now is CR% -- was there a click
  356. over a region? (The regions defined in
  357. 1200-1205)
  358.  
  359. .UN CR% -- and we keep looping until
  360. there is a click over a region. When
  361. CR% is Not Zero, the program falls
  362. through -- and we will handle the
  363. click.
  364.  
  365.     But first, we want to have the
  366. colors of the regions change with
  367. roll-overs. To complicate things, we
  368. need regions 1 - 4 change from cyan to
  369. light green, and region 5 change from
  370. yellow to orange.
  371.  
  372.     This sounds like a job for an
  373. array -- and an array we set up at the
  374. beginning of the program. Lets put it
  375. at line number 4000, then we can GOSUB
  376. to it at the top of the program.
  377.  
  378. 4000 dim c(1,5)
  379.  
  380. 4001 for x=1to4
  381.  
  382. 4002 c(0,x)=3:c(1,x)=13
  383.  
  384. 4003 next
  385.  
  386. 4004 c(0,5)=7:c(1,5)=8
  387.  
  388. 4005 return
  389.  
  390.     Actually, this is VERY straight-
  391. forward BASIC. We need each region to
  392. switch between color 0 to color 1. For
  393. the first 4, we use the FOR-NEXT loop
  394. the do the assignments. C(0,x) is the
  395. unhighlighted color. C(1,x) is the
  396. hightl