• 0

    posted a message on LibOOP
    I will look at that. Thank you sir. :)
    Posted in: Libraries
  • 0

    posted a message on LibOOP
    Hi Taleden,

    I am experimenting with your library but having some trouble regarding properties. Unfortunately, I have been unable to find any examples/tutorials where instance vars/properties are actually being used and did not locate any unit tests that exercised them.

    Specifically, I am not getting expected results after initializing a property in the overridden New() constructor. For the following class:

    Liboop = LibStub("LibOOP-1.0")
    
    Dog = Liboop:Class()
    Dog.prototype.happiness = "Neutral"
    
    function Dog:New(state)
       local o = self:Super('New')
       o.happiness = state
       return o
    end
    
    function Dog.prototype:Pet()
       if this.happiness == "Unhappy" then
          this.happiness = "Neutral"
       else
          this.happiness = "Happy"
       end
       print("Petted")
    end
    
    function Dog.prototype.Scold()
       this.happiness = "Unhappy"
       print("Scolded")
    end
    
    function Dog.prototype.Happy()
       return this.happiness
    end

    If I run this:
    local myDog = Dog("Neutral")
    print("property = "..myDog.happiness)
    print("Happy() = "..myDog.Happy())


    The result is an "attempt to concatenate a nil" error on the second print statement - myDog.Happy() is returning nil.
    If i run the following:

    local myDog = Dog("Neutral")
    myDog.Pet()
    print("property = "..myDog.happiness)
    print("Happy() = "..myDog.Happy())
    myDog.Pet()
    print("property = "..myDog.happiness)
    print("Happy() = "..myDog.Happy())
    myDog.Scold()
    print("property = "..myDog.happiness)
    print("Happy() = "..myDog.Happy())


    Then the property (myDog.happiness) and the instance method (myDog.Happy()) never have the same value. Clearly I am not doing this right. I have tried several variations but am not getting any satisfaction.

    I am new to Lua (but not programming or oo) so please forgive me if I have made a noob mistake, misusing the "syntactic sugar" or what-have-you.

    Any assistance you can offer would be most appreciated.

    P.S. Are you aware of any addons that are using Liboop? (I could really use some working examples).

    Thank you in advance
    Posted in: Libraries
  • To post a comment, please or register a new account.