Please forgive the total n00b question. I’m new to the Corona SDK (and programming in general, save for some VB and reading Frank Zammetti’s excellent book) and I’ve run into a problem. Having tried several things and searched extensively, I just can’t get my head around this…
Background: As a learning exercise I’m trying to write a game where there are six ‘thingies’. Each thingy will be given a ‘score’ based on random properties and the thingy with the highest score will be the “right” choice. The user will tap their choice and then they will be told if they have selected correctly or not.
I’m work on my ‘draw level’ function which will spawn the thingies. This function should produce 6 images on the screen and then make each of those six images identifiable by tap.
This is the code I’ve written:
for i=1,6,1 do
thingy[i] = display.newImageRect(“graphics/thingy.png”, 67, 122, true);
thingy[i].name = (“thingy”…i);
thingy[i].id = i;
thingy[i].x = (positionSpacing * i) - (positionSpacing / 2);
thingy[i].y = display.contentCenterY;
table.insert(thingy[i], gc.gameDG);
print(thingy[i].name…" “…thingy[i].x…” index "…thingy[i].id); --for debug
thingy[i]:addEventListener(“tap”, gc.positionTapped);
end
This creates the things on the screen happily. So then I define a function to react to the tapping of the thing:
function gc:positionTapped(event)
utils:log(sceneName, “positionSelected()”);
print(self.id);
end
The utils:log function is there for debug, and works correctly. But the print self.id doesn’t work. I’m expecting it to give me thingy id (which should be i as defined in the loop). It returns ‘nil’.
I tried changing the spawn loop to be:
for i=1,6,1 do
thingy[i] = display.newImageRect(“graphics/thingy.png”, 67, 122, true);
thingy[i].name = (“thingy”…i);
thingy[i].id = i;
thingy[i].x = (positionSpacing * i) - (positionSpacing / 2);
thingy[i].y = display.contentCenterY;
table.insert(thingy[i], gc.gameDG);
print(thingy[i].name…" “…thingy[i].x…” index "…thingy[i].id); --for debug
thingy[i]:addEventListener(“tap”, gc:positionTapped);
end
And the loop crashes out with “function arguments expected near )”
So I changed it again to be:
for i=1,6,1 do
thingy[i] = display.newImageRect(“graphics/thingy.png”, 67, 122, true);
thingy[i].name = (“thingy”…i);
thingy[i].id = i;
thingy[i].x = (positionSpacing * i) - (positionSpacing / 2);
thingy[i].y = display.contentCenterY;
table.insert(thingy[i], gc.gameDG);
print(thingy[i].name…" “…thingy[i].x…” index "…thingy[i].id); --for debug
thingy[i]:addEventListener(“tap”, gc:positionTapped());
end
and it crashes out with “Runtime error assertion failed!” during the loop, as does:
thingy[i]:addEventListener(“tap”, gc.positionTapped(thingy[i].id));
and so does:
thingy[i]:addEventListener(“tap”, gc.positionTapped(i));
I’ve been reading and googling for three days and still can’t find the answer. I’d be really thankful if you’d please take pity on a n00b and help me out. 
