Wait, Clear and Fre

7 replies [Last post]
Offline
Joined: Sep 4 2014
Posts: 21

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 (A) 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.

AttachmentSize
condensing_statements.jpg165.03 KB
__________________

"You can be in my dream if I can be in yours" / Bob Dylan

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mmphosis's picture
Offline
Joined: Aug 18 2005
Posts: 314
Re: Wait, Clear and Fre

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?

Offline
Joined: Sep 4 2014
Posts: 21
Re: Wait, Clear and Fre

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?

__________________

"You can be in my dream if I can be in yours" / Bob Dylan

mmphosis's picture
Offline
Joined: Aug 18 2005
Posts: 314
Re: Wait, Clear and Fre

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.

Offline
Joined: Sep 4 2014
Posts: 21
Re: Wait, Clear and Fre

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?

__________________

"You can be in my dream if I can be in yours" / Bob Dylan

Offline
Joined: Apr 11 2006
Posts: 1013
Re: Wait, Clear and Fre

RockbadgerX wrote:

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.

mmphosis's picture
Offline
Joined: Aug 18 2005
Posts: 314
Re: Wait, Clear and Fre

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 as PRINT AB$, and AB$ is empty so only a newline is displayed.
PRINT A;B$ separates the variables, and prints 1HI and a newline as expected.

Offline
Joined: Apr 11 2006
Posts: 1013
Re: Wait, Clear and Fre

mmphosis wrote:

PRINT CHR$(13);CHR$(4);"RUN DIFFERENT PROGRAM"

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.