Obviously this isn't OOP at all but, down a similar route to your original example, I quickly knocked this together.
// Create a few instances of the "person" class and set their properties
Global PlayerOne As Integer : PlayerOne = Person_New()
Person_SetAge(PlayerOne, 9001)
Person_SetName(PlayerOne, "Over 9,000!")
Global PlayerTwo As Integer : PlayerTwo = Person_New()
Person_SetAge(PlayerTwo, 8999)
Person_SetName(PlayerTwo, "Under 9,000!")
Global PlayerThree As Integer : PlayerThree = Person_New()
Person_SetAge(PlayerThree, 32)
Person_SetName(PlayerThree, "32 year old guy")
// Print the contents of the "person" instances
Person_Print(PlayerOne)
Person_Print(PlayerTwo)
Person_Print(PlayerThree)
// After a key press, dispose of an item and re-display
Print "Press any key"
Wait Key
Cls
Print "First item disposed"
Print ""
Person_Dispose(PlayerOne)
Person_Print(PlayerTwo)
Person_Print(PlayerThree)
// Exit after a key is pressed
Print "Press any key"
Wait Key
Person_DisposeAll()
End
// Define properties of the "person" class
Type PersonClass
Age As Integer
Name As String
EndType
// Method to dispose of a "person" class instance
Function Person_Dispose(_instanceId As Integer)
// Ensure the index supplied is with the collection
Local IndicesCount As Integer : IndicesCount = Array Count(PersonClassIndices())
If (IndicesCount >= _instanceId)
// Grab the actual index from the lookup
Local instanceId As Integer : instanceId = PersonClassIndices(_instanceId)
If (instanceId > -1)
// If the lookup index was the last then remove it, otherwise just reset it to -1
If (_instanceId < IndicesCount)
PersonClassIndices(_instanceId) = -1
Else
Array Delete Element PersonClassIndices(), IndicesCount
Dec IndicesCount
EndIf
// Remove the actual instance of the "person" class
Array Delete Element PersonClassInstances(), instanceId
// Check there are index lookups left
If (IndicesCount > -1)
// Loop through the index lookups
Local i As Integer
For i = IndicesCount To 0 Step -1
// Update to take into account the removed instance
If (PersonClassIndices(i) > instanceId)
Dec PersonClassIndices(i)
EndIf
Next i
// Attempt to delete any unused index lookups
i = IndicesCount
While (PersonClassIndices(i) = -1)
Array Delete Element PersonClassIndices(), i
Dec i
If (i = -1)
Exit
EndIf
EndWhile
EndIf
EndIf
EndIf
EndFunction
// Method to dispose of all instance of the "person" class
Function Person_DisposeAll()
// Clean up the instances and their index lookups
Empty Array PersonClassIndices()
Empty Array PersonClassInstances()
EndFunction
// Method to get the "age" property of an instance of the "person" class
Function Person_GetAge(_instanceId As Integer)
// Validate and lookup the actual instance index
Local age As Integer : age = 0
If (Array Count(PersonClassIndices()) >= _instanceId)
_instanceId = PersonClassIndices(_instanceId)
If (_instanceId > -1)
// Grab the "age" property
age = PersonClassInstances(_instanceId).Age
EndIf
EndIf
EndFunction age
// Method to get the "name" property of an instance of the "person" class
Function Person_GetName(_instanceId As Integer)
// Validate and lookup the actual instance index
Local name As String : name = ""
If (Array Count(PersonClassIndices()) >= _instanceId)
_instanceId = PersonClassIndices(_instanceId)
If (_instanceId > -1)
// Grab the "name" property
name = PersonClassInstances(_instanceId).Name
EndIf
EndIf
EndFunction name
// Class constructor for the "person" class
Function Person_New()
// Initialise if required
If (PersonClassInitialised = 0)
Global PersonClassInitialised As Boolean : PersonClassInitialised = 1
Global Dim PersonClassIndices() As Integer
Global Dim PersonClassInstances() As PersonClass
EndIf
// Insert the new instance and grab its index
Array Insert At Bottom PersonClassInstances()
Local index As Integer : index = Array Count(PersonClassInstances())
// Add a new item to the index lookup
Array Insert At Bottom PersonClassIndices()
PersonClassIndices() = index
index = Array Count(PersonClassIndices())
EndFunction index
// Method to print the properties of an instance of the "person" class
Function Person_Print(_instanceId As Integer)
// Validate and lookup the actual instance index
Local name As String : name = ""
If (Array Count(PersonClassIndices()) >= _instanceId)
_instanceId = PersonClassIndices(_instanceId)
If (_instanceId > -1)
// Print the details
Print "Age: " + Str$(PersonClassInstances(_instanceId).Age)
Print "Name: " + PersonClassInstances(_instanceId).Name
Print ""
EndIf
EndIf
EndFunction
// Method to set the "age" property of an instance of the "person" class
Function Person_SetAge(_instanceId As Integer, _age As Integer)
// Validate and lookup the actual instance index
If (Array Count(PersonClassIndices()) >= _instanceId)
_instanceId = PersonClassIndices(_instanceId)
If (_instanceId > -1)
// Set the "age" property
PersonClassInstances(_instanceId).Age = _age
EndIf
EndIf
EndFunction
// Method to set the "name" property of an instance of the "person" class
Function Person_SetName(_instanceId As Integer, _name As String)
// Validate and lookup the actual instance index
If (Array Count(PersonClassIndices()) >= _instanceId)
_instanceId = PersonClassIndices(_instanceId)
If (_instanceId > -1)
// Set the "name" property
PersonClassInstances(_instanceId).Name = _name
EndIf
EndIf
EndFunction
It creates a global dynamically sized array for instances of the class which you never access directly but add to via a class constructor which then returns a "pointer" for you to use in future. It also creates a second dynamic array which is just a collection of pointers to instances. This means that you can dispose of instances, which can be nice for memory usage with large numbers of large classes, without breaking any of your pointers.
To try and explain a bit better:
Global Player As Integer : Player = Person_New()
This creates a new instance of the "person" class and creates a pointer to it in the lookup collection and returns the index of the pointer. "Player" is now the reference you will use for all interactions with the class instance. The constructor also ensures the arrays are initialised the first time it is called.
Person_SetAge(Player, 12)
This takes the index that was created with the constructor, finds the pointer to the actual instance and then sets the "age" property on the instance to "12".
Person_Dispose(Player)
This takes the index that was created with the constructor, finds the pointer to the actual instance and then deletes the instance of the class. It resets the pointer in the lookup array and also cleans up the lookup array as much as possible by deleting any reset pointers at the end of the collection so as not to affect any still active indices.
Person_DisposeAll()
This clears out both the instances and their pointers entirely which would be useful for when the application state changes drastically and you need a clean start so you won't end up carrying global variables around needlessly. Whilst it isn't a huge amount, any memory you can claim back from the 2Gb limit is worth having!
Hope this at least slightly makes sense and might be of use to someone. Only tested it very briefly and it seems to work fine, but let me know if you need any help with it.
[Edit]Changing language on code snippet for syntax highlighting and a couple of typos in remarks.[/Edit]

Previously TEH_CODERER.