FreeCell
FreeCell SourceArray(), Element
 
Parameters:

    SourceArray() = The array you wish to free a cell from
    Element = The address of element you wish to free
Returns: NONE
 

      The FreeCell command frees a particular cell from within an array. It's primarily for use with String and Type arrays and you can use it with Integer and float arrays also. In which case, it just sets the cell to zero.



FACTS:


      * FreeCell is for use with Type and String arrays, but can also be used upon Integer,Floating Point arrays.




Mini Tutorial:


      This example creates a simple character manger using a typed array. When the type is no longer needed it's destroyed using the FreeCell command.



  
; Clear the Screen to Blue
  Cls RGB(0,0,255)
  
; Define a type to hold the values for our characters
  Type obj
     status,x,y,angle#,colour
  EndType
  
; Create the typed ships array to store our objects
  Dim Ships(0As obj
  
  
; LImit the program to 100 frames per second or less
  SetFPS 100
  
  
; start of program main loop
  Do
     
   ; clear the screen to black
     Cls RGB(0,0,0)
     
   ; Display Message
     Print "Press Space To Add Object"
     
   ; run through our array of objects
     For item=0 To GetArrayElements(ships().obj,1)
        
      ; check if this object exists or not
        If Ships(item).status
           
         ; move the object
           angle#=ships(item).angle#
           x#=CosNewValue(ships(item).x,angle#,2)
           y#=SinNewValue(ships(item).y,angle#,2)
           
         ; check if the obejct has left the screen
           If PointInBox(x#,y#,0,0,800,600)=false
            ; if it has, free this cell
              FreeCell Ships().obj,Item
              Continue
           EndIf
           
         ; object is on screen so draw it
           CircleC x#,y#,10,true,Ships(item).Colour
           
         ; write the objects new position
           ships(item).x=x#
           ships(item).y=y#
           
        EndIf
     Next
     
   ; check if the Space key is pressed
     If SpaceKey()
      ;if it is, get a free cell within the array
        Item=GetFreeCell(Ships().obj)
      ; assign it it's starting values
        Ships(Item).status=true
        ships(item).x=Rnd(800)
        ships(item).y=Rnd(600)
        ships(item).angle=Rnd(360)
        ships(item).colour=RndRGB()
        FlushKeys
     EndIf
     
   ; refresh the screen
     Sync
     
   ; loop back to the do statement to keep program running
  Loop
  


 
Related Info: ClearArray | ClearArrayCells | CopyArrayCells | NULL :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com