Associative Array Errors - n00b

Wow, that sounds important and useful - I really don’t understand most of that but I’ve copied it for future reference. I wish there was big advanced BrightScript tutorial from ground zero to that post that I could follow!

“Komag” wrote:
Wow, that sounds important and useful - I really don’t understand most of that but I’ve copied it for future reference. I wish there was big advanced BrightScript tutorial from ground zero to that post that I could follow!

What newmanliving is suggesting is implementing Objects and inheritance in BrightScript by using the AAs. I’ve done this in my own application, and it works very well. Here’s a very simple example which doesn’t handle calling super functions, or chaining constructors/destructors:


function objectCreate() as Object
   this = {}
   this._type = "Object"
   this.isType = function(typeName as String) as Boolean: return m._type = typeName: end function
   return this
end function

function personCreate(name as String) as Object
   this = objectCreate()

   ' Override Object's type with the new type "Person"
   this._type = "Person"

   ' Add members for Person and its subclasses
   this._name    = name
   this.getName = function() as String: return m._name: end function
   this.setName = function(name as String) as Void: m._name = name: end function

   ' Return our Person object
   return this
end function

function studentCreate(name as String, gradePointAverage as Float) as Object
   this = personCreate(name)

   ' Override Person's type with the new type "Student"
   this._type = "Student"

   ' Add members for Student and it's subclasses
   this._gpa = gradePointAverage
   this.getGPA = function() as Float: return m._gpa: end function
   this.setGPA = function(gradePointAverage as Float) as Void: m._gpa = gradePointAverage: end function

   ' Return our Student object
   return this
end function

function main() as Void
   people = []
   people.push(studentCreate("Billy", 3.1))
   people.push(studentCreate("Jane", 3.6))
   people.push(personCreate("John"))

   for each person in people
      ?"Person Named: ";person.getName()
      if person.isType("Student")
         ?"Student GPA: ";person.getGPA()
      end if
   end for
end function

In this example, each Student object inherits from Person which inherits from Object.
Note: I typed this directly on the page, so it might not compile. But the general idea is illustrated.

Thanks, I’ll go through that and learn from it, I appreciate it :slightly_smiling_face: