[Resolved] Issue with localGroup:insert

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]

Move; localGroup:insert(buttonCover); --this is the problem

to line 327 - then change to;
localGroup:insert(buttonCover[totalButtons])

I believe that should do the trick- please let me know.

Peach :slight_smile: [import]uid: 52491 topic_id: 32330 reply_id: 128705[/import]

That removed all errors allright, but now none of the buttonCovers show up in my game… It looks like this now:

[lua]

–Set a cover to hide the button image

buttonCover[totalButtons] = display.newImage(“button.png”);
localGroup:insert(buttonCover[totalButtons]);
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(button);
localGroup:insert(restart);
localGroup:insert(menu);
[/lua]
This is just a new account by the way…

EDIT: So I have been trying different stuff, and whenever the error shows up the buttons show up normally and work fine, however, every time the game doesn’t find an error the buttons disappear. [import]uid: 190275 topic_id: 32330 reply_id: 128749[/import]

Okay, now I got it to work!

In addition to adding localGroup:insert(buttonCover[totalButtons]) to the line you said I added localGroup:insert(button[count]) to line 308.

So now the bottom looks like this:

[lua]–knappeplassering
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”);
localGroup:insert(button[count]) --added to work
–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”);
localGroup:insert(buttonCover[totalButtons]) – added to work
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

–for countI = 0, table.getn(buttonCover)/2 do

–end

– localGroup:insert(button);
localGroup:insert(restart);
localGroup:insert(menu);

– buttonCover[totalButtons] = display.newImage(“button.png”);

return localGroup;

end

[/lua]

Thanks so much for the help! [import]uid: 190275 topic_id: 32330 reply_id: 128751[/import]

@ht5629,

Just curious, but what school are you attending and what class are you taking? I ask because I am interested in how Corona SDK is being used in schools.

  • Ed [import]uid: 110228 topic_id: 32330 reply_id: 128764[/import]

I attend Høgskolen i Nord Trønderlag, Norway. Working on my bachelor in game- and experience(as in “wow, that was quite an experience”)-design. Corona is used pretty much for all mobile development along with Unity3d. This particular class is called “Multimedia and mobile devices”. [import]uid: 189956 topic_id: 32330 reply_id: 128773[/import]

Move; localGroup:insert(buttonCover); --this is the problem

to line 327 - then change to;
localGroup:insert(buttonCover[totalButtons])

I believe that should do the trick- please let me know.

Peach :slight_smile: [import]uid: 52491 topic_id: 32330 reply_id: 128705[/import]

No worries, glad to help. Marking as resolved.

PS - Ed, please don’t use makeshift sigs. We will support sigs soon but for now makeshift is against guidelines; http://developer.coronalabs.com/forum/2011/05/05/forum-rules-and-guidelines - thanks.

Peach :slight_smile: [import]uid: 52491 topic_id: 32330 reply_id: 128816[/import]

Peach,

  1. Thanks for the notice. I’m used to posting with signatures over at the GarageGames forums, but that’s no excuse. I should have read the guidelines.

  2. I it looks like you or someone else has been doing some cleaning, but I found a few old posts that still have my signatures in them.
    I can clean these up, but I’m afraid that doing so will move them to the ‘Active Discussions’ column which could block folks from getting attention on their threads.

Do you want me to:
A. Leave them alone,

B. Clean them myself, or

C. Leave it to you folks.

To avoid polluting the thread with more links I’ve placed the links to these files in a text file here.
3. Lastly, I am looking forward to the signature feature. It will be useful and a time saver.

Thanks again,
Ed
[import]uid: 110228 topic_id: 32330 reply_id: 128819[/import]

That removed all errors allright, but now none of the buttonCovers show up in my game… It looks like this now:

[lua]

–Set a cover to hide the button image

buttonCover[totalButtons] = display.newImage(“button.png”);
localGroup:insert(buttonCover[totalButtons]);
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(button);
localGroup:insert(restart);
localGroup:insert(menu);
[/lua]
This is just a new account by the way…

EDIT: So I have been trying different stuff, and whenever the error shows up the buttons show up normally and work fine, however, every time the game doesn’t find an error the buttons disappear. [import]uid: 190275 topic_id: 32330 reply_id: 128749[/import]

Okay, now I got it to work!

In addition to adding localGroup:insert(buttonCover[totalButtons]) to the line you said I added localGroup:insert(button[count]) to line 308.

So now the bottom looks like this:

[lua]–knappeplassering
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”);
localGroup:insert(button[count]) --added to work
–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”);
localGroup:insert(buttonCover[totalButtons]) – added to work
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

–for countI = 0, table.getn(buttonCover)/2 do

–end

– localGroup:insert(button);
localGroup:insert(restart);
localGroup:insert(menu);

– buttonCover[totalButtons] = display.newImage(“button.png”);

return localGroup;

end

[/lua]

Thanks so much for the help! [import]uid: 190275 topic_id: 32330 reply_id: 128751[/import]

@ht5629,

Just curious, but what school are you attending and what class are you taking? I ask because I am interested in how Corona SDK is being used in schools.

  • Ed [import]uid: 110228 topic_id: 32330 reply_id: 128764[/import]

I attend Høgskolen i Nord Trønderlag, Norway. Working on my bachelor in game- and experience(as in “wow, that was quite an experience”)-design. Corona is used pretty much for all mobile development along with Unity3d. This particular class is called “Multimedia and mobile devices”. [import]uid: 189956 topic_id: 32330 reply_id: 128773[/import]

No worries, glad to help. Marking as resolved.

PS - Ed, please don’t use makeshift sigs. We will support sigs soon but for now makeshift is against guidelines; http://developer.coronalabs.com/forum/2011/05/05/forum-rules-and-guidelines - thanks.

Peach :slight_smile: [import]uid: 52491 topic_id: 32330 reply_id: 128816[/import]

Peach,

  1. Thanks for the notice. I’m used to posting with signatures over at the GarageGames forums, but that’s no excuse. I should have read the guidelines.

  2. I it looks like you or someone else has been doing some cleaning, but I found a few old posts that still have my signatures in them.
    I can clean these up, but I’m afraid that doing so will move them to the ‘Active Discussions’ column which could block folks from getting attention on their threads.

Do you want me to:
A. Leave them alone,

B. Clean them myself, or

C. Leave it to you folks.

To avoid polluting the thread with more links I’ve placed the links to these files in a text file here.
3. Lastly, I am looking forward to the signature feature. It will be useful and a time saver.

Thanks again,
Ed
[import]uid: 110228 topic_id: 32330 reply_id: 128819[/import]

Hey Ed-

Sorry for the late reply, was off for the weekend.

First up - I greatly appreciate your response; thanks for understanding. I know some forums do accept this, certainly. Soon we will have a new forum and then we will have sig options.

Until then no, you absolutely don’t have to edit your old posts - if any of us see sigs like that we’ll likely snip them but we aren’t obsessive about it, especially when it’s unintentional.

Please do post your links in any thread where you can work them into the post appropriately - spreading links is just fine, just no sigs. (Soon!)

Thanks :slight_smile:

Peach [import]uid: 52491 topic_id: 32330 reply_id: 129133[/import]

Hey Ed-

Sorry for the late reply, was off for the weekend.

First up - I greatly appreciate your response; thanks for understanding. I know some forums do accept this, certainly. Soon we will have a new forum and then we will have sig options.

Until then no, you absolutely don’t have to edit your old posts - if any of us see sigs like that we’ll likely snip them but we aren’t obsessive about it, especially when it’s unintentional.

Please do post your links in any thread where you can work them into the post appropriately - spreading links is just fine, just no sigs. (Soon!)

Thanks :slight_smile:

Peach [import]uid: 52491 topic_id: 32330 reply_id: 129133[/import]