Corona SDK (Lua) with OOP

I am trying to make my code structured by adopting OOP (object-oriented) concept

With that in mind, other than putting all my game logic in scene file (am using Corona StoryBoard)

Currently, creating a board game

And in order to make them more sense, i call each module an ACTOR (score, board, countdown timer)

Each actor has process their own game logic (that’s my intension)

I inited all my modules beginning of the lua file in Scene LUA file

local score = require 'score' local board = require 'board' local countdowntm = require 'countdowntm'

When i start program, it’s look clean & easy. But after awhile, when the game logic grown, i found it quite tough.

E.g. in my board.lua file, i have a method

    function board:gameFinish()              .. diff code logic         score:calculateGameScore...     end

    

each ACTOR are interrelated, they are calling each other in order to perform their own game logic (e.g. score calculate scoring logic, board detect game states, etc…)

But corona keeps on complain error, nil, but i think it would be great if they are GLOBAL and visible to each other (problem is how to do that?)

Thanks for your time reading and i hope to get some advices from corona/lua gurus. 

Regards,

Weilies

Repeat your require statements in each of your actor modules.

The way I do it, is to create a global table, that contains all ACTORs as you call them. It looks like the following in each module.

[LUA]

–leaderboard.lua

local game_handler = game_handler --game_handler is the global table

local leaderboard = {}

game_handler.leaderboard = leaderboard

require ‘score’

require ‘board’

require ‘countdowntm’

–functions and other stuf here

[/LUA]

Each submodule lloks like the following:

[LUA]

–score.lua

local game_handler = game_handler

local leaderboard = game_handler.leaderboard

local score = {}

leaderboard.score = score

–functions and other stuff here

[/LUA]

The nice thing about this is, that you can refference from any module to any other module if you want to.

Repeat your require statements in each of your actor modules.

The way I do it, is to create a global table, that contains all ACTORs as you call them. It looks like the following in each module.

[LUA]

–leaderboard.lua

local game_handler = game_handler --game_handler is the global table

local leaderboard = {}

game_handler.leaderboard = leaderboard

require ‘score’

require ‘board’

require ‘countdowntm’

–functions and other stuf here

[/LUA]

Each submodule lloks like the following:

[LUA]

–score.lua

local game_handler = game_handler

local leaderboard = game_handler.leaderboard

local score = {}

leaderboard.score = score

–functions and other stuff here

[/LUA]

The nice thing about this is, that you can refference from any module to any other module if you want to.