Problems with multi-file games

  1. 7 weeks ago
    Edited 6 weeks ago by jeff

    After I saw the demoplatformer I realized how much I liked the multi-file approach to programming. After relentlessly trying to wrap my head around idea I think I've figured it out, except how to use "self."
    example:

    class "Crab"
    
    function Crab:Crab()
    self.posX = 0
    end
    
    function Crab:Update(elapsed)
    self.posX = self.posX + 3
    end

    This code spits out attempt to perform arithmetic on field 'posX' (a nil value)
    What am I missing?C

  2. fodinabor

    Feb 9 Administrator

    don't miss to declare class "Crab" at the beginning of the file

  3. 6 weeks ago

    @fodinabor don't miss to declare class "Crab" at the beginning of the file

    My fault, but still, after adding that it still doesn't work want to work.

  4. fodinabor

    Feb 10 Administrator

    you created the Crab object before by calling crab = Crab() ?
    No other idea, as I'm not using Lua..

 

or Sign Up to reply!