Friday, November 22, 2013

Petit Computer Journal #26

A Simple Interactive Story Reader

I am currently busy with Nanowrimo, and in the story, there is a program that lets student write their own interactive stories. Even knowing how little it takes to do it, I'm rather surprised at the economy of it. Here is the program in its entirety:


  1. REM INIT
  2. CLEAR:TITLE$=""
  3. DIM TEXT$[10]
  4. DIM PAGE$[4]
  5. DIM MENU$[4]
  6. CH=0:P$="INTRO"

  7. @SHOWPAGE
  8. RESTORE P$
  9. READ TITLE$
  10. READ TEXT$[0]:READ TEXT$[1]
  11. READ TEXT$[2]:READ TEXT$[3]
  12. READ TEXT$[4]:READ TEXT$[5]
  13. READ TEXT$[6]:READ TEXT$[7]
  14. READ TEXT$[8]:READ TEXT$[9]
  15. READ PAGE$[0]:READ MENU$[0]
  16. READ PAGE$[1]:READ MENU$[1]
  17. READ PAGE$[2]:READ MENU$[2]
  18. READ PAGE$[3]:READ MENU$[3]

  19. REM DISPLAY
  20. CLS:?TITLE$:?
  21. ?TEXT$[0]:?TEXT$[1]
  22. ?TEXT$[2]:?TEXT$[3]
  23. ?TEXT$[4]:?TEXT$[5]
  24. ?TEXT$[6]:?TEXT$[7]
  25. ?TEXT$[8]:?TEXT$[9]
  26. ?"1",MENU$[0]
  27. ?"1",MENU$[1]
  28. ?"1",MENU$[2]
  29. ?"1",MENU$[3]

  30. REM INPUT
  31. INPUT CH:CH=CH-1
  32. P$=PAGE$[CH]
  33. GOTO @SHOWPAGE




If the structure isn't clear to you, you need to add LABEL and DATA statements. Here's a sampling that I have. Notice, the DATA segments do go on, although each having the same structure.

  1. REM WINDELL

  2. @INTRO
  3. DATA "THE STORY OF WINDELL"
  4. DATA "ONCE UPON A TIME THERE WAS A"
  5. DATA "LITTLE RAT BY THE NAME OF"
  6. DATA "WINDELL."
  7. DATA " "
  8. DATA "SHE WAS HUNGRY AND IN SEARCH"
  9. DATA "OF CHEESE. WHERE DO YOU THINK"
  10. DATA "SHE SHOULD GO?"
  11. DATA " "
  12. DATA " "
  13. DATA " "
  14. DATA "KITCH","TO THE KITCHEN"
  15. DATA "BEDRO","TO THE BEDROOM"
  16. DATA "BADEND","STAY HOME"
  17. DATA "INTRO"," "

The DATA segments consist of a LABEL, 1 line TITLE, 10 lines TEXT, and 4 lines LABEL/CHOICE combo. Obviously there's also @KITCH, @BEDRO, and @BADEND DATA segments. There's also @GOODEND data segment, too!

The beauty of it is that the story can be long and involved. The size of the program stays the same regardless. This is a good introduction for computer programming, those of you who are just beginning. Obviously, it can be refined further. How about full screen text on top, and 8 or more choices on the bottom? Simple enough to enhance and experiment with.




No comments:

Post a Comment