After creating my first game in more or less one huge file, I am having a go at using modules in my next game.
My first task I am attempting is to create a module that will create a score display at the top of my game screen composed of X number of graphical digits.
I have created the following module which is successfully displaying the digits but I am having a problem passing a score value to a function in this module. I am sure it is something fundmental I am missing out here with regards scoping but can’t figure it out.
Here is my code for scoreboard.lua
module( ..., package.seeall )
-- Generates A New Scoreboard
function newScoreboard( params )
if not params.spacing or params.spacing == "" then params.spacing = 10 end
if not params.digits or params.digits == "" then params.digits = 6 end
local scoreboard = display.newGroup()
local digitAnim
for i =1, params.digits do
digitAnim = movieclipRetina.newAnim({ "images/score/score0.png", "images/score/score1.png", "images/score/score2.png", "images/score/score3.png", "images/score/score4.png", "images/score/score5.png", "images/score/score6.png", "images/score/score7.png", "images/score/score8.png", "images/score/score9.png", }, 10,17)
digitAnim.x = 0 + (params.spacing \* (i - 1))
digitAnim.y = 0
scoreboard:insert(digitAnim)
end
scoreboard.x = params.posX
scoreboard.y = params.posY
function scoreboard:updateScoreDisplay(score)
print ("passed score " .. score)
if score \< 10 then
print ("passed score less than 10")
end
end
return scoreboard
end
And here is the code in main.lua where I create the scoreboard
local scoreboardClass= require("scoreboard")
local movieclipRetina = require("movieclipRetina")
-- Add A New Scoreboard
local scoreboard = scoreboardClass.newScoreboard{
spacing = 10,
digits = 6,
posX = 10,
posY = 10
}
scoreboard.updateScoreDisplay(3)
It is the last line of code here that is causing the error:
attempt to concatenate local ‘score’ (a nil value)
Any help much appreciated
Thanks
Paul [import]uid: 7863 topic_id: 15308 reply_id: 315308[/import]