Problems with multi-file games

  1. 6 months ago
    Edited 6 months 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

    9 Feb 2017 Administrator

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

  3. @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

    10 Feb 2017 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!