home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-09-28 | 5.1 KB | 184 lines |
- '***************************
- '* AMOS Professional * INSTRUCTIONS COVERED
- '* *
- '* PROCEDURES 1 * Procedure
- '* * End Proc
- '* (c) Europress Software * Proc
- '* *
- '* Ronnie Simpson *
- '***************************
- '
- '-------------------------------------------
- 'GENERAL
- '-------------------------------------------
- 'Procedures allow a program to be developed in small 'modules' which can be
- 'easily tested and de-bugged individually without getting bogged down in
- 'lengthy lists of code.
- 'They have several advantages over the alternative subroutine and each can
- 'have its own set of variables,data lists and program lines which are
- 'independant of the main program and other procedures.
- 'Once you have mastered the basics of working with procedures then I am sure
- 'that most of your future programming will make liberal use of these
- 'powerful aids.
- '-------------------------------------------
- 'Setting up a simple procedure
- '-------------------------------------------
- ' Procedure NAME
- ' : :
- ' : :
- ' End Proc
- '
- 'A procedure is identified by giving it a name, this can be any legal string
- 'of characters just like your variables.
- 'Each procedure must be terminated by the instruction End Proc.
- 'Both 'Procedure' and 'End Proc must be given their own individual lines.
- 'Everything inside the procedure will be ignored by the program until the
- 'procedure is called, this is done by entering the procedure name at any
- 'point in the program.
- '
- 'eg. WARNING
- ' '
- ' Procedure WARNING
- ' Print "smoking can damage your health"
- ' End Proc
- '
- 'To avoid any confusion the optional 'Proc' instruction may be used.
- '
- 'eg Proc WARNING
- '
- 'Always leave a space between the procedure name and the colon when using
- 'multi-statemaent lines or the instruction will be interpreted as a lable.
- '
- 'eg. WARNING: Print "incorrect" (this would define the lable WARNING)
- ' WARNING : Print "correct" (this would call the procedure)
- '
- '-------------------------------------------
- 'Procedure variables
- '-------------------------------------------
- 'Normally all variables used in a procedure are 'local' or independant from
- 'the rest of the program, it is therfore perfectly feasible to have
- 'the same variable name with 2 to more different values in the same program
- 'depending on whether they are inside or outside the procedures.
- '
- 'eg A=100
- ' Proc REDHERRING
- ' Proc REDHERRING
- ' Print A
- ' Print C
- ' End
- ' '
- ' Procedure REDHERRING
- ' B=200 : C=A+B
- ' Print C
- ' End Proc
- 'Try to work out what the 4 values are that would be printed if this program
- 'was run, bearing in mind that:-
- ' (1) 'A' and 'C' can have different values inside the procedure.
- ' (2) 'B' and 'C' are local variables to the procedure
- ' (3) Local variables are flushed (assigned a value of zero) each time
- ' the procedure is used.
- '
- 'Answer at line 179 at the bottom of this listing.
- '
- 'There are ways you can transfer information to and from a procedure and
- 'these are dealt with in the Procedures_2 tutorial.
- '
- '------------------------------------------- '
- 'WORKING EXAMPLE
- '-------------------------------------------
- Rem *** set out screen
- '
- Screen Open 0,640,200,16,Hires : Flash Off : Hide
- Palette $0,$F00,$F0,$F,$FF0,$F0F,$FF,$F70,$7F,$70F,$F07,$333,$666,$999,$CCC,$FFF
- Curs Off : Cls 0 : Paper 0 : Pen 6
- Locate 1,1 : Centre Border$("A PROVERB A DAY KEEPS THE DOCTOR AWAY!",3)
- Locate 0,20 : Centre "LEFT MOUSE KEY FOR ANOTHER PROVERB RIGHT MOUSE KEY TO QUIT"
- '
- '
- Rem *** start main loop
- '
- Do
- '
- '
- Rem *** call the 3 procedures
- '
- Proc BEGINING
- Proc MIDDLE
- Proc FINISH
- '
- '
- Rem *** wait for a mouse click
- '
- Wait 50
- Do
- M=Mouse Key
- Exit If M
- Loop
- Exit If M=2
- '
- '
- Rem *** clear the old proverb and repeat or quit
- Cline
- Loop
- Edit
- '
- '
- Rem *** the procedures
- '
- Procedure BEGINING
- Pen(Rnd(9)+1)
- Locate Rnd(15)+5,Rnd(12)+5
- R=Rnd(8)+1 : Restore(R)
- Read A$
- Print A$+" ";
- 1 Data "A ROLLING STONE"
- 2 Data "A STITCH"
- 3 Data "A BIRD IN THE HAND"
- 4 Data "ALL THAT GLITTERS"
- 5 Data "EVERY CLOUD"
- 6 Data "TOO MANY COOKS"
- 7 Data "TIME AND TIDE"
- 8 Data "PEOPLE IN GLASS HOUSES"
- 9 Data "THE PEN"
- 10 Data "NECESSITY"
- End Proc
- '
- Procedure MIDDLE
- R=Rnd(9)+1 : Restore(R+10)
- Read A$
- Print A$+" ";
- 11 Data "GATHERS NO"
- 12 Data "IN TIME SAVES"
- 13 Data "IS WORTH 2 IN THE"
- 14 Data "IS NOT"
- 15 Data "HAS A SILVER"
- 16 Data "SPOILS THE"
- 17 Data "WAITS FOR NO"
- 18 Data "SHOULD NOT THROW"
- 19 Data "IS MIGHTIER THAN THE"
- 20 Data "IS THE MOTHER OF"
- End Proc
- '
- Procedure FINISH
- R=Rnd(9)+1 : Restore(R+20)
- Read A$
- Print A$+" ";
- 21 Data "MOSS"
- 22 Data "NINE"
- 23 Data "BUSH"
- 24 Data "GOLD"
- 25 Data "LINING"
- 26 Data "BROTH"
- 27 Data "MAN"
- 28 Data "STONES"
- 29 Data "SWORD"
- 30 Data "INVENTION"
- End Proc
- '
- '--------------------
- 'answer to problem:-
- ' 200
- ' 200
- ' 100
- ' 0
- '--------------------