localGroup:insert problem

local t = {}  
  
 t[1] = 1  
 t[2] = 3  
 t[3] = 5  
 t[4] = 4  
 t[5] = 7  
 t[6] = 6  
 t[7] = 2  
 t[8] = 4  
 t[9] = 14  
  
 t[10] = 11  
 t[11] = 4  
 t[12] = 8  
 t[13] = 6  
 t[14] = 5  
 t[15] = 11  
 t[16] = 8  
 t[17] = 2  
 t[18] = 11  
  
 for l = 1,#t,1 do   
  
 if (l \<= 9) then  
 local txt = display.newText(l, 250, 93+(l-1)\*38,nil,35)  
 txt.rotation = 90  
 txt.xScale = .5  
 txt.yScale = .5  
 txt.x =270  
 txt:setTextColor(50, 50, 50)  
  
 local txt = display.newText(t[l], 200, 93+(l-1)\*38,nil,35)  
 txt.rotation = 90  
 txt.xScale = .5  
 txt.yScale = .5  
 txt.x = 220  
 txt:setTextColor(50, 50, 50)  
 end  
 if (l \>= 10) then  
  
 local txt = display.newText(l, 250, 93+(l-10)\*38,nil,35)  
 txt.rotation = 90  
 txt.xScale = .5  
 txt.yScale = .5  
 txt.x =150  
 txt:setTextColor(50, 50, 50)  
  
 local txt = display.newText(t[l], 200, 93+(l-10)\*38,nil,35)  
 txt.rotation = 90  
 txt.xScale = .5  
 txt.yScale = .5  
 txt.x = 100  
 txt:setTextColor(50, 50, 50)  
 end  
 end  

when i try to do localGroup:insert(txt) director doesn’t work. When i leave it without the localGroup:insert(txt) the numbers go to the next scene. Has anyone had the same problem?
[import]uid: 24708 topic_id: 19805 reply_id: 319805[/import]

Which line number are you calling localGroup:insert(txt) at? [import]uid: 120 topic_id: 19805 reply_id: 76797[/import]

sorry i didnt post that ill post my whole code.

[code]

module(…, package.seeall)
function new()
local localGroup = display.newGroup()
local background = display.newImage(“scorecard.png”, 320, 480)
background.x = 160
background.y = 240

local button1 = display.newImage(“images/button1.png”, 320, 480)
button1.x = 20
button1.y = 50
button1.xScale = .5
button1.yScale = .5
button1.rotation = 90

local btn1txt = display.newText(“Menu”, 0, 0, native.systemFontBold, 25)
btn1txt.x = 20
btn1txt.y = 50
btn1txt.rotation = 90

function button1activate(e)
if(e.phase == “began”) then

director:changeScene(“menu”)
end
end

local t = {}

t[1] = 1
t[2] = 3
t[3] = 5
t[4] = 4
t[5] = 7
t[6] = 6
t[7] = 2
t[8] = 4
t[9] = 14
t[10] = 11
t[11] = 4
t[12] = 8
t[13] = 6
t[14] = 5
t[15] = 11
t[16] = 8
t[17] = 2
t[18] = 11

for l = 1,#t,1 do

if (l <= 9) then
local txt = display.newText(l, 250, 93+(l-1)*38,nil,35)
txt.rotation = 90
txt.xScale = .5
txt.yScale = .5
txt.x =270
txt:setTextColor(50, 50, 50)

local txt = display.newText(t[l], 200, 93+(l-1)*38,nil,35)
txt.rotation = 90
txt.xScale = .5
txt.yScale = .5
txt.x = 220
txt:setTextColor(50, 50, 50)
end
if (l >= 10) then

local txt = display.newText(l, 250, 93+(l-10)*38,nil,35)
txt.rotation = 90
txt.xScale = .5
txt.yScale = .5
txt.x =150
txt:setTextColor(50, 50, 50)

local txt = display.newText(t[l], 200, 93+(l-10)*38,nil,35)
txt.rotation = 90
txt.xScale = .5
txt.yScale = .5
txt.x = 100
txt:setTextColor(50, 50, 50)
end
end

button1:addEventListener(“touch”, button1activate)
localGroup:insert(background)
localGroup:insert(button1)
localGroup:insert(btn1txt)
localGroup:insert(txt) – this doesnt work

return localGroup;
end
[/code] [import]uid: 24708 topic_id: 19805 reply_id: 76807[/import]

looks like txt is out of scope. try inserting it into localGroup inside of the if statements in your for loop. [import]uid: 120 topic_id: 19805 reply_id: 76809[/import]

You need to put that straight after each of the setTextColor statements.

But probably the best method is to add localGroup as the first parameter of the newText function, like this:

local txt = display.newText(localGroup, t[l], 200,

I just tried this i thought it worked at first but it doensn;t [import]uid: 24708 topic_id: 19805 reply_id: 76812[/import]

Make sure you have it in there twice though…

You have 2 different objects called txt inside the loop.
If you only do the insert once, you will get the most recent txt object only.
[import]uid: 108660 topic_id: 19805 reply_id: 76813[/import]

do it this way then…
if (l >= 10) then

local txt = display.newText(localGroup ,l, 250, 93+(l-10)*38,nil,35)
txt.rotation = 90
txt.xScale = .5
txt.yScale = .5
txt.x =150
txt:setTextColor(50, 50, 50)

local txt = display.newText(localGroup ,t[l], 200, 93+(l-10)*38,nil,35)
txt.rotation = 90
txt.xScale = .5
txt.yScale = .5
txt.x = 100
txt:setTextColor(50, 50, 50)
end [import]uid: 108660 topic_id: 19805 reply_id: 76814[/import]

 for l = 1,#t,1 do   
  
 if (l \<= 9) then  
 local txt = display.newText(l, 250, 93+(l-1)\*38,nil,35)  
 txt.rotation = 90  
 txt.xScale = .5  
 txt.yScale = .5  
 txt.x =270  
 txt:setTextColor(50, 50, 50)  
  
  
 local txt = display.newText(t[l], 200, 93+(l-1)\*38,nil,35)  
 txt.rotation = 90  
 txt.xScale = .5  
 txt.yScale = .5  
 txt.x = 220  
 txt:setTextColor(50, 50, 50)  
  
  
 localGroup:insert(txt)  
  
 end  
 if (l \>= 10) then  
  
 local txt = display.newText(l, 250, 93+(l-10)\*38,nil,35)  
 txt.rotation = 90  
 txt.xScale = .5  
 txt.yScale = .5  
 txt.x =150  
 txt:setTextColor(50, 50, 50)  
  
  
 local txt = display.newText(t[l], 200, 93+(l-10)\*38,nil,35)  
 txt.rotation = 90  
 txt.xScale = .5  
 txt.yScale = .5  
 txt.x = 100  
 txt:setTextColor(50, 50, 50)  
  
 localGroup:insert(txt)  
 end  
 end  

I think you mean this… This wasn’t working cause i believe that it is only applying to the latest txt.
Im going to try to change the names between the first and the second one [import]uid: 24708 topic_id: 19805 reply_id: 76815[/import]

No, I really didn’t.

When I said “Make sure you have it in there twice though…”
I was warning you about the problem where it would only work on the latest txt.

I really mean do it like this:

local txt = display.newText(localGroup ,l, 250, 93+(l-10)*38,nil,35)

because that adds to the group at the point of creation, all in one shot.
If you insist upon using localGroup:insert(txt)

then you need

 if (l \>= 10) then  
  
 local txt = display.newText(l, 250, 93+(l-10)\*38,nil,35)  
 txt.rotation = 90  
 txt.xScale = .5  
 txt.yScale = .5  
 txt.x =150  
 txt:setTextColor(50, 50, 50)  
 localGroup:insert(txt)  
  
 local txt = display.newText(t[l], 200, 93+(l-10)\*38,nil,35)  
 txt.rotation = 90  
 txt.xScale = .5  
 txt.yScale = .5  
 txt.x = 100  
 txt:setTextColor(50, 50, 50)  
  
 localGroup:insert(txt)  
 end  

and it won’t matter that they have the same names.
[import]uid: 108660 topic_id: 19805 reply_id: 76816[/import]

sorry about the misinterpretations. I originally did it both ways but it didn’t seem to work. Then i realized that the text was under the background i originally had.

Sorry for the confusion, and thanks for your help! [import]uid: 24708 topic_id: 19805 reply_id: 76818[/import]