Director class function not working??

Hi,

Im using director class version 1.3, the problem is that i have one block of code that does not work once i have director class in and the main.lua says to change to level1 wich is the file the code is in. I had a lot more code before and everything works fine except the code below, i can’t figure out why?
Everything works fine until i put it into level1.lua, it just has no effect. Anyone know why?

THANKS.

The code that is not working in level1.lua , the main.lua says to change to level1.

– I can’t figure out why it does not work…

[code]
local i = 1
local tempLine
local ractgangle_hit = {}
local prevX , prevY
local function runTouch(event)
if(event.phase==“began”) then
if(tempLine==nil) then
tempLine=display.newLine(event.x, event.y, event.x, event.y)
tempLine.alpha = 0
– Random Colors for line

r = math.random (0, 255)
g = math.random ( 0, 255)
b = math.random (0, 255 )
tempLine:setColor(r,g, b)

prevX = event.x
prevY = event.y
end
elseif(event.phase==“moved”) then
tempLine:append(event.x,event.y-2)
tempLine.width=tempLine.width+0.9
ractgangle_hit[i] = display.newLine(prevX, prevY, event.x, event.y)
ractgangle_hit[i]:setColor(r,g, b)
ractgangle_hit[i].width = 4

– Creates physic joints for line (Turn on draw mode to see the effects)

local Width = ractgangle_hit[i].width * 0.5
local Height = ractgangle_hit[i].height * 0.19

– Physic body for the line shape

local lineShape = {-Width,-Height,Width,-Height,Width,Height,-Width,Height}

physics.addBody(ractgangle_hit[i], “static”, { bounce = -1, density=0, friction=0.7, shape = lineShape})
prevX = event.x
prevY = event.y
i = i + 1
elseif(event.phase==“ended”) then
tempLine.parent.remove(tempLine)
tempLine=nil

if limit > 0 then
limit = limit - 1
end
end
end
Runtime:addEventListener(“touch”, runTouch)
[import]uid: 23689 topic_id: 13765 reply_id: 313765[/import]

can I see the full content of level1.lua ?
make sure you have all the below essential parts

[lua]module(…, package.seeall)
–should have a new() function and it should return a local displaygroup
function new()
local localGroup = display.newGroup()

–add all display objects to localGroup

–return localGroup
return localGroup
end[/lua] [import]uid: 71210 topic_id: 13765 reply_id: 50584[/import]

Hi,

Thanks for your response. Should that be added to level1.lua ?

Thanks again.

The code on my level1.lua :

[code]
local ui = require(“ui”)

display.setStatusBar( display.HiddenStatusBar )

soundtrack = audio.loadStream(“Maxime game.m4a”)
–audio.play(soundtrack, {loops = -1})

physics = require (“physics”)
physics.start()
–physics.setDrawMode “hybrid”
physics.setGravity(0, 15)

stockphoto = display.newImageRect (“stockphoto.png”,500,500)
stockphoto.x = display.contentWidth/2
stockphoto.y = display.contentHeight/2

topbar = display.newImageRect (“woodtop.png”,100,630)
topbar.x = display.contentWidth/2.1
topbar.y = display.contentHeight/13.2
topbar.rotation = 90

– Draw a line
limit =160
local scoreTxt = display.newText(“100”,250,20,native.systemFont,20)
local i = 1
local tempLine
local rectangle_hit = {}
local prevX , prevY
local function runTouch(event)
if(event.phase==“began”) then
if(tempLine==nil) then
tempLine=display.newLine(event.x, event.y, event.x, event.y)

– Random Colors for line

r = math.random (0, 255)
g = math.random ( 0, 255)
b = math.random (0, 255 )
tempLine:setColor(r,g, b)

prevX = event.x
prevY = event.y
end
elseif(event.phase==“moved”) then
tempLine:append(event.x,event.y-2)
tempLine.width=tempLine.width+0.9
rectangle_hit[i] = display.newLine(prevX, prevY, event.x, event.y)
rectangle_hit[i]:setColor(r,g, b)
rectangle_hit[i].width = 5
tempLine.alpha = 0

– Creates physic joints for line (Turn on draw mode to see the effects)

local Width = rectangle_hit[i].width * 0.6
local Height = rectangle_hit[i].height * 0.2

– Physic body for the line shape

local lineShape = {-Width,-Height,Width,-Height,Width,Height,-Width,Height}

physics.addBody(rectangle_hit[i], “static”, { bounce = -1, density=0.3, friction=0.7, shape = lineShape})
prevX = event.x
prevY = event.y
i = i + 1
elseif(event.phase==“ended”) then
tempLine.parent.remove(tempLine)
tempLine=nil
end
end
Runtime:addEventListener(“touch”, runTouch)

local ball = display.newCircle( 0, 0, 12.5)
ball:setFillColor(0, 255, 0)
ball.x = display.contentWidth/1.1
ball.y = display.contentHeight/4

local function moveHeavens(e)
scoreTxt.text = limit
if limit < 0 then
scoreTxt.text = 0
end
end

Runtime:addEventListener(“enterFrame”, moveHeavens )

ring = display.newImage “ringhoop.png”
ring.x = display.contentWidth/100
ring.y = display.contentHeight/1.8
ring.alpha = 0.5
–physics.addBody( ring, {friction =0.1, radius = 65,isSensor = true, bounce = 0.1})
–ring.linearDamping = 100
–local function wassup( self, event )

–tempLine = false

–end

–ring.collision = wassup
–ring:addEventListener( “collision”, ring)
local scaleFactor = 0.20
local physicsData = (require “mybthoop”).physicsData(scaleFactor)
local hoop= display.newImageRect (“thehoop.png”,63,93)
hoop.x = display.contentWidth/15.5
hoop.y = display.contentHeight/1.8
physics.addBody( hoop, “static”,physicsData:get(“hoop”) )
hoop.isBodyActive = false
point = 0
local function pointPlus(e)
if (point == 1) then
golda = display.newImageRect (“gold.png”,30,30)
golda.x = display.contentWidth/25
golda.y = display.contentHeight/10

golda.alpha= 0
transition.to(golda, { time=2000, alpha=1} )

end
end

Runtime:addEventListener(“enterFrame”, pointPlus )

local function pointPlus1(e)
if (point == 2) then
goldc = display.newImageRect (“gold.png”,30,30)
goldc.x = display.contentWidth/13
goldc.y = display.contentHeight/10
goldc.alpha= 0
transition.to(goldc, { time=2000, alpha=1} )
end
end

Runtime:addEventListener(“enterFrame”, pointPlus1 )

local function pointPlus2(e)
if (point == 3) then
goldb = display.newImageRect (“gold.png”,30,30)
goldb.x = display.contentWidth/9
goldb.y = display.contentHeight/10
goldb.alpha= 0
transition.to(goldb, { time=2000, alpha=1} )

end
end

Runtime:addEventListener(“enterFrame”, pointPlus2 )
gold1 = display.newImageRect (“gold.png”,30,30)
gold1.x = display.contentWidth/1.4
gold1.y = display.contentHeight/2
physics.addBody(gold1, “static”,{radius = 15,isSensor = true})
gold1.isBodyActive = false

gold2 = display.newImageRect (“gold.png”,30,30)
gold2.x = display.contentWidth/3.7
gold2.y = display.contentHeight/2
physics.addBody(gold2, “static”,{radius = 15,isSensor = true})
gold2.isBodyActive = false

gold3 = display.newImageRect (“gold.png”,30,30)
gold3.x = display.contentWidth/2
gold3.y = display.contentHeight/2.5
physics.addBody(gold3, “static”,{radius = 15,isSensor = true})
gold3.isBodyActive = false
local w,h = display.contentWidth, display.contentHeight

score = 0

ball.myName = “ball”
gold1.myName = “gold1”

ball:addEventListener(“collision”, ball)

function ball:collision (event)
if event.other.myName == “gold1” and score==0 then

transition.to( gold1, { time=400, alpha=0, x=(w/1.4), y=(h/4) } )
point = point + 1
score = score +1

end
end
score1 = 0
gold2.myName = “gold2”
ball.myName = “ball”

gold2:addEventListener(“collision”, gold2)

function gold2:collision (event)
if event.other.myName == "ball"and score1==0 then

transition.to( gold2, { time=400, alpha=0, x=(w/3.6), y=(h/4) } )
point = point +1
score1 = score1 +1
end
end

score2 = 0

ball.myName = “ball”
gold3.myName = “gold3”

gold3:addEventListener(“collision”, gold3)

function gold3:collision (event)
if event.other.myName == "ball"and score2==0 then

transition.to( gold3, { time=400, alpha=0, x=(w/2), y=(h/4) } )
point = point +1
score2 = score2 +1

end
end

function button2Press(event)

drop.isVisible = true
Renew.isVisible = false
end
Renew = ui.newButton{
default = “Renew.png”,
over = “Renew.png”,
onPress = button2Press,
emboss = true
}

Renew.x = display.contentWidth/1.1
Renew.y = display.contentHeight/12
Renew.rotation = 0
Renew.isVisible = false






button1Press = function( event )
physics.addBody(ball, {bounce=0.3, radius = 12.5, friction=0.5, density = 200})
drop.isVisible = false
Renew.isVisible = true
gold1.isBodyActive = true
gold2.isBodyActive = true
gold3.isBodyActive = true
hoop.isBodyActive = true
tempLine = false

end

drop = ui.newButton{
default = “drop.png”,
over = “drop.png”,
onPress = button1Press,
emboss = true
}
drop.x = display.contentWidth/1.1
drop.y = display.contentHeight/12
drop.rotation = 0

local button1Press = function( event )

for i = 1, #rectangle_hit, 1 do
rectangle_hit[i]:removeSelf()
rectangle_hit[i] = nil

goldr = display.newImageRect (“gold.png”,30,30)
goldr.x = display.contentWidth/1.4
goldr.y = display.contentHeight/2
physics.addBody(goldr, “static”,{radius = 15,isSensor = true})
goldr.isBodyActive = false

goldr2 = display.newImageRect (“gold.png”,30,30)
goldr2.x = display.contentWidth/3.7
goldr2.y = display.contentHeight/2
physics.addBody(goldr2, “static”,{radius = 15,isSensor = true})
goldr2.isBodyActive = false

goldr3 = display.newImageRect (“gold.png”,30,30)
goldr3.x = display.contentWidth/2
goldr3.y = display.contentHeight/2.5
physics.addBody(gold3r, “static”,{radius = 15,isSensor = true})
goldr3.isBodyActive = false

end
end

local hi = ui.newButton{
default = “drop.png”,
over = “drop.png”,
onPress = button1Press,
emboss = true
}

hi.x = display.contentWidth/14
hi.y = display.contentHeight/12
[import]uid: 23689 topic_id: 13765 reply_id: 50628[/import]

yea you have to do that for Director to load the Screen.
[import]uid: 71210 topic_id: 13765 reply_id: 50672[/import]