passing a parameter to a function in a module

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]

personally i dont see a problem in your code, its seems just fine…
i tried it myself and it works like it should
main.lua
[lua]local classC = require(“class”)

local score = classC.newScoreBoard{
left = 150,
top = 150,
width = 100,
height = 50
}

score:update(5)[/lua]

class.lua
[lua]module(…, package.seeall)
function newScoreBoard( params )

local scoreboard = display.newGroup()

local board = display.newRect(0,0,0,0)
board.x = params.left
board.y = params.top
board.width = params.width
board.height = params.height
scoreboard:insert(board)

function scoreboard:update(score)
if score > 10 then
print(“more than ten”)
elseif score < 10 then
print("passed score: "…score)
end
end

return scoreboard
end[/lua] [import]uid: 16142 topic_id: 15308 reply_id: 56510[/import]

Hey thanks darkconsoles - I can see the error now. You have score:update(5) whereas I have used a dot instead of a colon. Doh!

Thanks for helping me spot this:) [import]uid: 7863 topic_id: 15308 reply_id: 56511[/import]