Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Komag
Roku Guru

Re: 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!
0 Kudos
Rek
Visitor

Re: Associative Array Errors - n00b

"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.
0 Kudos
Komag
Roku Guru

Re: Associative Array Errors - n00b

Thanks, I'll go through that and learn from it, I appreciate it 🙂
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.