Wait, Clear and Fre

8 posts / 0 new
Last post
Offline
Last seen: 9 years 7 months ago
Joined: Sep 3 2014 - 21:33
Posts: 21
Wait, Clear and Fre
AttachmentSize
Image icon condensing_statements.jpg165.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 Angel 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.

mmphosis's picture
Offline
Last seen: 2 weeks 1 day ago
Joined: Aug 18 2005 - 16:26
Posts: 442
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
Last seen: 9 years 7 months ago
Joined: Sep 3 2014 - 21:33
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?

mmphosis's picture
Offline
Last seen: 2 weeks 1 day ago
Joined: Aug 18 2005 - 16:26
Posts: 442
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
Last seen: 9 years 7 months ago
Joined: Sep 3 2014 - 21:33
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?

Offline
Last seen: 9 years 1 month ago
Joined: Apr 10 2006 - 20:01
Posts: 1013
Re: Wait, Clear and Fre

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
Last seen: 2 weeks 1 day ago
Joined: Aug 18 2005 - 16:26
Posts: 442
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
Last seen: 9 years 1 month ago
Joined: Apr 10 2006 - 20:01
Posts: 1013
Re: Wait, Clear and Fre

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.

Log in or register to post comments