Attachment | Size |
---|---|
condensing_statements.jpg | 165.03 KB |
Hi. Could somebody please explain the when and why to use the CLEAR and X=FRE(0) commands?
How do I use the WAIT command? I used to know...
Thank you for showing me how to simplify my programs as shown in the attachment. (The shaded area reduced to two lines).
Also, I get a Bad Subscript Error if my is greater than 10. I am assuming that you cannot have a value greater than 10 as such a variable. Otherwise, suggestions welcome.
Thanks, again.
http://www.landsnail.com/a2ref.htm
Use CLEAR when you want to clear all variables in one fell swoop: numbers to zero, strings to empty, functions to undefined, arrays back to the default single dimension of 0 to 10. You might also want to CLEAR memory when "redimensioning" arrays.
Use X = FRE(0) when you want the variable X to be assigned the value of the amount of memory available, and when you want to free up available memory. This is helpful when a program is running low on memory, but be aware that the FRE function may cause a delay when freeing up memory.
Wait until memory location masked by second argument equals third argument (or zero). For example, when you want to WAIT for a keypress you may use WAIT 49152, 128
At the beginning of your program, use DIM A(255) or DIM A( as large an array as you need ), you can also define multi-dimensional arrays: DIM A(15,15,15) or DIM X%(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) as examples.
Why you would want to do all these things? Why not?
Yes, why not...
When I was a teenager in the eighties I would program my own RPGs along the lines of Eamon's games. Everything worked great, and by the end I was doing stuff like Translvania thanks to the Graphics Magician. All in Basic. However, my programming was always cumbersome (especially when I looked at the programming of others).
Now I'm reliving those days, and want to learn how to do many of the things I couldn't work out (WHY????). Imagine if we had the internet back then... instead of purchasing a monthly copy of Nibble and typing in 4 pages of code only to find the program didn't work and ruthlessly crosschecking every line to find out the flaw was in the original documentation... grrr.
I digress.
In answer to your question why? I believe then when you run one program from another all variables are set to zero anyway (hence READ/WRITE). But is the memory actually cleansed?
When you run one program from another, like this ...
PRINT CHR$(4)"RUN DIFFERENT PROGRAM"
... the memory is "cleansed."
There is also an Applesoft CHAIN program on the system master disk which allows you to run one program from another but preserves the variables, but not the function definitions.
Ah, and I know I read the answer to this elsewhere...
But I notice that you did not use a semicolon. What effect does the semi-colon have on your example line?
None. But as you learned before, you do need to start a disk command on a "new line" or it won't get interpreted as a command.
Thanks David, with a newline and semi-colons...
PRINT CHR$(13);CHR$(4);"RUN DIFFERENT PROGRAM"
and yes, semicolons are usually optional. Here is an exception...
]
A = 1 : B$ = "HI"
]
PRINT A B$
]
PRINT A;B$
1HI
PRINT A B$
is the same asPRINT AB$
, andAB$
is empty so only a newline is displayed.PRINT A;B$
separates the variables, and prints 1HI and a newline as expected.The CHR$(13) isn't usually necessary, of course - but RockbadgerX had some code that had HTAB'd itself across the screen, then tried to do a CHR$(4) disk command in the middle of it. So he'd really only need a return if here were still in some HTAB position.