First of all, I am a total noob, this is a school assignment and I have no idea what I’m doing.
The problem I have is with inserting buttonCover into localgroup, I have tried many different things, like localGroup:insert(buttonCover[totalButtons]) and localGroup:insert(button[count]). I am totally lost…
the error I get is:
Director ERROR: Failed to execute new( params ) function on ‘game’
c:\users\name\desktop\huskespillet\game.lua:343: bad argument #-2 to ‘insert’
(proxy expected, got nil)
[lua]
module(…, package.seeall)
function new()
local localGroup = display.newGroup();
_W = display.contentWidth;
_H = display.contentHeight;
display.setStatusBar(display.HiddenStatusBar);
local restart = display.newImage(“restart.png”, 168, 27);
restart:setReferencePoint(display.CenterReferencePoint);
restart.x = _W/2;
restart.y = 85;
restart.isVisible = false;
restart.alpha = 0;
restart.scene = “game”;
local menu = display.newImage(“menu.png”, 104, 27);
menu:setReferencePoint(display.CenterReferencePoint);
menu.x = _W/2;
menu.y = 175 + menu.height;
menu.isVisible = false;
menu.alpha = 0;
menu.scene = “menu”;
function changeScene(e)
if(e.phase == “ended”) then
director:changeScene(e.target.scene);
print(“works??”)
end
end
restart:addEventListener(“touch”, changeScene );
menu:addEventListener(“touch”, changeScene);
local volumeOn = display.newImageRect ( “volumeon.png”, 60, 28 )
volumeOn:setReferencePoint(display.CenterReferencePoint);
volumeOn.x= 30 volumeOn.y = 468
volumeOn.isVisible = true;
volumeOn.alpha = 1;
local volumeOff = display.newImageRect ( “volumeoff.png”, 60, 28 )
volumeOff:setReferencePoint(display.CenterReferencePoint);
volumeOff.x= 30 volumeOff.y = 468
volumeOff.isVisible = false;
volumeOff.alpha = 0;
function turnOff()
audio.setVolume (0)
print(“SOUND OFF”)
volumeOff.isVisible = true;
volumeOff.alpha = 1;
volumeOn.isVisible = false;
volumeOn.alpha = 0;
end
function turnOn()
audio.setVolume ( 0.5 )
print (“SOUND ON”)
volumeOn.isVisible = true;
volumeOn.alpha = 1;
volumeOff.isVisible = false;
volumeOff.alpha = 0;
end
volumeOff:addEventListener(“tap”, turnOn);
volumeOn:addEventListener(“tap”, turnOff);
local ego = require “ego”
local saveFile = ego.saveFile
local loadFile = ego.loadFile
local score = 0
local numBtn = 12
local newHighScore = false
local totalButtons = 0
local secondSelect = 0
local checkForMatch = false
x = -20
local cheer = audio.loadSound(“sound.wav”)
local boo = audio.loadSound(“boo.wav”)
–Spelledaase
local playCheer = function()
audio.play(cheer)
end
local playBoo = function()
audio.play(boo)
end
–SJEKKER OM highscore ER LAGRET
local function checkForFile ()
if highscore == “empty” then
highscore = -99
saveFile(“highscore.txt”, highscore)
print (“asdasdasdasdasd”)
end
highscore = loadFile (“highscore.txt”)
if highscore == “empty” then
highscore = -99
end
end
checkForFile()
–Knapper
local button = {}
local buttonCover = {}
local buttonImages = {1,1, 2,2, 3,3, 4,4, 5,5, 6,6}
local lastButton = display.newImage(“1.png”);
lastButton.myName = 1;
localGroup:insert(lastButton);
–Bakgrunn
local bg = display.newImageRect(“bakgrunn.png”, _W, _H);
bg:setReferencePoint(display.CenterReferencePoint);
bg.x = _W/2; bg.y = _H/2;
localGroup:insert(bg);
–notifikasjoner te speglaren
local scoreText = display.newText("Score: " …score, 0, 0, native.systemFont, 24)
scoreText:setTextColor( 240, 240, 240 )
scoreText:setReferencePoint(display.CenterReferencePoint)
scoreText.x = _W/2
localGroup:insert(scoreText);
local matchText = display.newText (" ", 0, 0, native.systemFont, 26)
matchText:setReferencePoint(display.CenterReferencePoint)
matchText:setTextColor(255, 255, 255)
matchText.x = _W/2 matchText.y = 50
localGroup:insert(matchText);
–highscore functiona
local function addToScore()
score = score + 1
scoreText.text = score
end
local function subtractFromScore()
score = score - 1
scoreText.text = ("Score: " …score)
end
local function checkHighScoreFile()
print (score)
print(highscore)
if score > tonumber (highscore) then
newHighScore = true
saveFile(“highscore.txt”, highscore)
end
end
local function subtractFromNumBtn()
numBtn = numBtn -2
if (numBtn == 0) then
checkHighScoreFile()
highscore = loadFile (“highscore.txt”)
restart.isVisible = true;
menu.isVisible = true;
transition.to(restart, {time=1000, alpha = 1});
transition.to(menu, {time=1000, alpha = 1});
if newHighScore == true then
print (“Highscore is”, score)
scoreText.text = ("New highscore!: "…score)
else
print (“Highscore is”, highscore)
scoreText.text = ("Highscore is still: "…highscore)
end
end
end
–speglfunktiona
function game(object, event)
if(event.phase == “began”) then
if(checkForMatch == false and secondSelect == 0) then
–flippngavandrekyrtet
buttonCover[object.number].isVisible = false;
lastButton = object
checkForMatch = true
elseif(checkForMatch == true) then
if(secondSelect == 0) then
–Flip over second button
buttonCover[object.number].isVisible = false;
secondSelect = 1;
–hvis det ikke matcher, flippe tilbake
if(lastButton.myName ~= object.myName and lastButton ~= object) then
matchText.text = “Match Not Found!”;
playBoo()
subtractFromScore()
timer.performWithDelay(1250, function()
matchText.text = " ";
checkForMatch = false;
secondSelect = 0;
buttonCover[lastButton.number].isVisible = true;
buttonCover[object.number].isVisible = true;
end, 1)
–hvis knappene fungerer, fjerne de
elseif(lastButton.myName == object.myName and lastButton ~= object) then
matchText.text = “Match Found!”;
playCheer()
addToScore()
subtractFromNumBtn()
timer.performWithDelay(1250, function()
matchText.text = " ";
checkForMatch = false;
secondSelect = 0;
lastButton:removeSelf();
object:removeSelf();
buttonCover[lastButton.number]:removeSelf();
buttonCover[object.number]:removeSelf();
end, 1)
else
timer.performWithDelay(1250, function()
matchText.text = " ";
checkForMatch = false;
secondSelect = 0;
buttonCover[lastButton.number].isVisible = true;
buttonCover[object.number].isVisible = true;
end, 1)
end
end
end
end
end
–quitsave
local function onSystemEvent ()
if score > tonumber(highscore) then --We use tonumber as highscore is a string when loaded
saveFile(“highscore.txt”, score)
newHighScore = true
end
end
Runtime:addEventListener( “system”, onSystemEvent )
–buttonplacement
for count = 1,3 do
x = x + 90
y = 20
for insideCount = 1,4 do
y = y + 90
–Assign each image a random location on grid
temp = math.random(1,#buttonImages)
button[count] = display.newImage(buttonImages[temp] … “.png”);
–Position the button
button[count].x = x;
button[count].y = y;
–Give each a button a name
button[count].myName = buttonImages[temp]
button[count].number = totalButtons
–Remove button from buttonImages table
table.remove(buttonImages, temp)
–Set a cover to hide the button image
buttonCover[totalButtons] = display.newImage(“button.png”);
buttonCover[totalButtons].x = x; buttonCover[totalButtons].y = y;
totalButtons = totalButtons + 1
–Attach listener event to each button
button[count].touch = game
button[count]:addEventListener( “touch”, button[count] )
end
end
localGroup:insert(buttonCover); --this is the problem
localGroup:insert(button); --this also I think
localGroup:insert(restart);
localGroup:insert(menu);
return localGroup;
end[/lua] [import]uid: 189956 topic_id: 32330 reply_id: 332330[/import]