Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
(SOLVED)How can we send int parameter to the class — Gideros Forum

(SOLVED)How can we send int parameter to the class

mertocanmertocan Member
edited April 2012 in General questions
I want to send point variable to the any class from main as a parameter, and i want to return it . In the class it should be changable. The point can be increased or decreased. Then, i should be able to use the point in the main again. Can you give any examples which satisfy that?

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Do you mean simple setters/getters?
    MyClass = Core.class(Sprite)
     
    function MyClass:init(myValue)
       self.value = myValue
    end
     
    function MyClass:setValue(newValue)
       self.value = newValue
    end
     
    function MyClass:getValue()
       return self.value
    end
     
    function MyClass:increase(byValue)
       self.value = self.value + byValue
    end
     
    function MyClass:decrease(byValue)
       self.value = self.value - byValue
    end
    Example usage:
    --initial value 10
    local myInstance = MyClass.new(10)
    --increase by ten
    myInstance:increase(10)
    --returns 20
    local val = myInstance:getValue()
     
    --set initial value to 100
    myInstance:setValue(100)
    --decrease by 50
    myInstance:decrease(50)
    --returns 50
    local val2 = myInstance:getValue()
  • I should have thought about that :) Thank you again :)
Sign In or Register to comment.