Kids getting their own games out of f3: 
this is kidpop23, getting started with 
with arrays and "doing bubbles" for sorting 
 
 
***Adults: you will find instructive programs and 
occasionally useful comments inside the KIDPOPnn series, 
where bits and pieces not discussed in F3DOCS are shown. 
So it has value for you, too! 
 
 
Written by Aristo 
 
 
 
  
***HI KIDS!!! 
Do you know what? If you want to make your own games and  
think clearly and think also funnily -- quickly, seeing 
things in a new way, understanding things quickly -- 
then it is good to know also a little bit about that 
which we call "arrays". You might exclaim, when you see 
three cool cafees beside one another on a map, -- hey, 
that's a whole array of cool cafees! -- and so, by array 
we simply mean something beside one another. Some might 
say a "list", but the word array is finer.
  The PC can do lots of things for you fast. But you 
have to tell it, or somebody has to do it. 
  And when we want the PC to fix on an array of numbers 
so that they are all increasing -- upwards, you know -- 
then we are doing -- or the PC is doing, rather -- what 
we can call "sorting". We get the computer to sort the 
list, oops, I mean array. Array sorting.
  So the simplest way to begin to program the PC to do 
sorting, so that we really see, step by step, how it is 
doing it, is to compare any two numbers beside one 
another.
  And if any two beside one another is in the wrong 
sequence, then we switch the sequence. Alright? We use 
something called %GTSWITCH. The funny little sign in 
front of GTSWITCH, which means, 'switch these two 
numbers in the array if the one on the left is greater 
than the one on the right' -- that funny little sign 
means that we're doing arrays. If you view this inside 
the B9, you know, the place where we make a program and 
fix on it and store it, before running it with IN, then 
the little funny thing before GTSWITCH is shown as a 
nice thingy going up, and spreading like a flower. 
  But when you type in things directly inside F3, to 
test one or other things how they work, without putting 
them all up in a good fine document, there is a 
different look to the letters and the numbers. And also 
this little sign then look like 0/0 or something, -- it 
is by some called "percentage". 
  In any case, when we have a list, I mean an array, 
then we can sort it by going through again and again 
with this %GTSWITCH. For large arrays we have other ways 
of sorting, but you can learn a lot when you are 
starting to learn how to program games by looking at 
various examples of things just with numbers. And so it 
is a good rule to be patient, to learn to love numbers 
but at the same time, don't use these numbers when you 
compare your bodies. Numbers are numbers, bodies are 
bodies, let's not give each other numbers, thank you 
very much. I mention this since you will work a lot lot 
with numbers but only sometimes is it right to give 
these numbers to ourselves. 
  Are you working by yourself right now, or with a 
teacher? The teacher might have put this neat little 
program in a file called BUBSORT.TXT first, so that you 
can test the program, and THEN we talk a little bit 
about how it works. You test it then by typing  
  F3
and press ENTER, and you type  
  :BUBSORT  IN
and press ENTER. Then you just follow the flow and watch  
how it works, step by step, until you've seen enough, 
and you press the letter it tells you to press to quit 
the program.
 
(LET BUBSORT BE (( )) 
  ((
    (( }Hi! For fun, making some numbers..} => POP ))
    (( 20 ; 1000 => %RFFG => & ))
    (( GOLABEL1: ))
    (( # => %SEE ))
    (( }Press B to bubble'em, or X to finish} => POP ))
    (( KEY ; :X => EQ = && ; RAM-REFRESH ; EXIT === ))
    (( 19
      (COUNT
        (( N1 ; N1 INC ; # => %GTSWITCH ))
      COUNTUP) ))
    (( GOUP1 ))
  )) OK)
(LET AUTOSTART BE BUBSORT OK) 
  
Do you understand what it is to "bubble" the numbers? 
Every time two beside one another are not quite right, 
it switches around these two, and so on, and so the 
littlest numbers travel to the left, while the biggest 
ones travel to the right. The line is a little bit too 
long to show so some numbers might go over the line, but 
that's good when you know it. 
  And, after many like these, the list is no longer 
changing! It is finished, it is sorted, the %GTSWITCH no 
longer switches anything around. And you press X and 
leave it, rather than yet another B to sort it.
  The array COULD have a thousand numbers. And these 
numbers COULD big really big, like a million or even 
hundreds of times bigger than that again, -- still it 
would go fairly fast. Another time we might look at 
other ways of sorting, which allows you to sort not just 
numbers on their own, but, say, also numbers along with 
some text of some kind. All sorts of things like this 
might be useful to know to make your own thoughts clear 
and also to make games and such.
  So don't be too impatient with getting on to really 
game-like programs if you want to learn games: have fun 
in doing things ONLY with numbers and ONLY with letters 
before you add it all up to good games. And as I said, 
it is also about getting to know how your own mind 
works, getting it sharper, better to meditate, better 
energy to your mind. And you learn how to draw for you 
see more clearly new things when you have done your bit 
with programming, say, earlier the day or week.
  So there are all sorts of benefits with programming.
  In any case, before we look at that BUBSORT, how it 
works, let us realize that the PC could do the same with 
much much less of the (( and the )) and the ; and the =>  
for these things are there just to straighten it out, as  
when you put your hair in pigtails. 
  So, just so you know it, the PC could do with 
something like this also -- which is the same bunch as 
above but written like a mess, without lineshifts in the 
proper places, without extra blanks: 
 
(LET BUBSORT }Hi! For fun, making some numbers..} POP  
20 1000 %RFFG & GOLABEL1: # %SEE  
}Press B to bubble'em, or X to finish} POP KEY :X EQ = &&  
RAM-REFRESH EXIT === 19 (COUNT N1 N1 INC # %GTSWITCH  
COUNTUP) GOUP1 OK) (LET AUTOSTART BUBSORT OK)  
  
Now the big key to this is (COUNT .. COUNTUP). If you 
count the numbers in the array when it shows them to you 
-- which it does by the %SEE word -- and it has made the  
numbers by the %RFFG word -- you will see that it is 
twenty of them. Each time you do the program there is a 
new array of numbers, different than the earlier, but 
they are all within one and thousand. And you see one 
and thousand, 1 and 1000, are given to %RFFG so whenever 
you see RFFG you should trust that this is a good type 
of coincidence, the FF is for Free Fluctuation, a free 
dance, G is for Generate, or make, and R is for Rather, 
Relative. Anyway, just trust RFFG. The word also exists 
in FUNNYRFFG, another way of doing it. And also we use 
the word FR sometimes, for the same. 
  Anyway, there are twenty of them. So there is a 19, 
one less than twenty, before the (COUNT. This is 
because we want to look at all the neigbours -- all the 
numbers beside one another, and the rightmost pair is 19 
and 20, not 20 and 21, for 21 doesn't here exist in this  
array. Right? So we put 19 before the (COUNT and then 
the N1 inside the (COUNT .. COUNTUP) goes from 1 and up 
to 19. And so we instruct the PC to look at 1 and 2, 
then 2 and 3, then 3 and 4, and up to 19 and 20. So we 
use the word INC -- do you find it? -- for INC means 
increase, get the number up by 1 -- so we give the 
%GTSWITCH the instruction to look at both N1 and also N1 
INC. That's all there is to it. 
  There are some funny letters or what we call them -- 
characters -- there, as well. These are just places to 
store what we are looking at, so we don't have to make a 
new list each time. The # contains as it were the array.  
When we use the & on its own, this sign is also called 
"and", for you can use it English as a quick way of 
writing and, such as when you say: I will walk & then 
swim. So here we use the AND to say, we will store this 
& use it more. It can be an array or it can be a table, 
like a game-board, then we call it "matrix". 
  So that's it. Then & starts the storing of the array, 
after we made it by %RFFG. Then the && tells the PC that 
we are done with the array, otherwise a peculiar number 
will appear when the PC gets the instruction to meditate 
and sleep and have a bath, which is what RAM-REFRESH and  
EXIT does. And in between the & and the && we tell the 
PC to work with the array by the # or "number" symbol.
  What else? Oh yes, the word KEY tells the computer to 
fetch a letter or such from the keyboard, and the :X 
tells the PC to compare with an uppercase X, and the 
word EQ tells the computer to make whatever is typed 
into uppercase (so you can type x not just X) and 
compare it. When EQ -- which is short for EQual texts -- 
gets going hot, then what is inside the = and the === 
gets done. The = is also called 'equals', and three of 
them means that we are done.
  Then GOUP1 tells the PC to do the same type of thing 
over again, but with the new updated number list. It 
goes then faithfully up, just as you ask it, to 
GOLABEL1:. Each program can have up to four such, 
GOLABEL1: to GOLABEL4:, and one such label can have one 
and but one GO to it, and the GO is either GOUP, as 
here, or GOFORWARD, when it is further on.
  What happens to the list of the numbers when the 
program finishes? Nothing is really lost but all gets 
refreshed and gets fresh use, in new programs, -- new 
bodies, as it were, the numbers being a kind of souls 
and spirits. So they get turned around as the new 
programs in the future wants, but such that everything 
important is kept.
  See you soon!!!