12:39:31.002 ERROR: Runtime error
12:39:31.002 C:\Users\User\Documents\Corona Projects\MATH FOR CHILDREN\level1.lua:207: attempt to call method 'setFillColor' (a nil value)
12:39:31.002 stack traceback:
12:39:31.002 C:\Users\User\Documents\Corona Projects\MATH FOR CHILDREN\level1.lua:207: in function 'listener'
12:39:31.002 D:\a\corona\corona\subrepos\timer\timer.lua:331: in function 'method'
12:39:31.002 D:\a\corona\corona\platform\resources\init.lua:220: in function <D:\a\corona\corona\platform\resources\init.lua:189>
This is my code
local composer = require("composer");
local scene = composer.newScene();
local widget = require( "widget" )
local json = require("json")
display.setDefault("background", 55/255, 50/255, 47/255);
------------------------------------------------------------------------------------
local tapText
local casi = display.newText( "a", display.contentCenterX, 700, "Myfontilqar-Regular.ttf", 42 )
casi:setFillColor(0/255,196/255,253/255,1)
local yes = display.newText( "c", display.contentCenterX, 700, "Myfontilqar-Regular.ttf", 46 )
yes:setFillColor(6/255,204/255,36/255,1)
local no = display.newText( "b", display.contentCenterX, 700, "Myfontilqar-Regular.ttf", 44 )
no:setFillColor(219/255,26/255,15/255,1)
local bal
local balpl
local vrem
local scetcikBal = 0
local scetcikBalpl = 0
local scetcikLevel = 0
local settings = {
yesJ = 0, noJ = 0, procent = 0, procent2 = 0
}
local function saveSettings()
local path = system.pathForFile( "itoq.json", system.DocumentsDirectory )
local file = io.open( path, "w" )
if (file) then
local contents = json.encode(settings)
file:write( contents )
io.close( file )
return true
end
end
local secondL = 20
local function obnovVr( event )
secondL = secondL - 1
vrem.text = secondL
if secondL == 0 then
settings.yesJ = scetcikBal
settings.noJ = scetcikBalpl
settings.procent = (scetcikBal * 10)
saveSettings()
composer.gotoScene( "Level1Score")
end
end
local kor = {
{display.contentCenterX - 66, display.contentCenterY + 120},
{display.contentCenterX + 70, display.contentCenterY + 120},
{display.contentCenterX - 66, display.contentCenterY + 200},
{display.contentCenterX + 70, display.contentCenterY + 200}
}
local tb = {
{"1 + 2 = ?",{"3","2","4","1"},"1 + 2 = 3"},
{"2 + 3 = ?",{"5","4","6","3"},"2 + 3 = 5"},
{"3 + 1 = ?",{"4","3","5","1"},"3 + 1 = 4"},
{"2 + 2 = ?",{"4","2","3","1"},"2 + 2 = 4"},
{"3 + 2 = ?",{"5","3","4","1"},"3 + 2 = 5"},
{"1 + 1 = ?",{"2","5","4","1"},"1 + 1 = 2"},
{"1 + 3 = ?",{"4","1","5","2"},"1 + 3 = 4"},
{"2 + 1 = ?",{"3","2","1","4"},"2 + 1 = 3"},
{"4 + 1 = ?",{"5","3","4","1"},"4 + 1 = 5"},
{"1 + 4 = ?",{"5","4","2","3"},"1 + 4 = 5"}
}
local j
for i = #tb, 2, -1 do
j = math.random( i )
tb[i], tb[j] = tb[j], tb[i]
end
local j1
for i = #kor, 2, -1 do
j1 = math.random( i )
kor[i], kor[j1] = kor[j1], kor[i]
end
local button1
local button2
local button3
local button4
nVoprosa = 1
local t = 2
local function stop1()
button1:setEnabled( false )
button2:setEnabled( false )
button3:setEnabled( false )
button4:setEnabled( false )
tapText.text = tb[nVoprosa][3]
tapText:setFillColor(6/255, 204/255, 36/255, 1)
end
local function stop2()
button1:setEnabled( false )
button2:setEnabled( false )
button3:setEnabled( false )
button4:setEnabled( false )
tapText.text = tb[nVoprosa][3]
tapText:setFillColor(219/255, 26/255, 15/255, 1)
tapText.size = 50
end
local function vb()
t = t - 1
if t == 0 then
scetcikBal = scetcikBal + 1
bal.text = scetcikBal
scetcikLevel = scetcikLevel + 1
if ( scetcikLevel == 10) then
settings.yesJ = scetcikBal
settings.noJ = scetcikBalpl
settings.procent = (scetcikBal * 10)
saveSettings()
composer.gotoScene( "Level1Score")
else
button1:setEnabled( true )
button2:setEnabled( true )
button3:setEnabled( true )
button4:setEnabled( true )
tapText:setFillColor(255/255, 255/255, 255/255, 1 )
nVoprosa = nVoprosa + 1
tapText.text = tb[nVoprosa][1]
button1:setLabel( tb[nVoprosa][2][1] )
button2:setLabel( tb[nVoprosa][2][2] )
button3:setLabel( tb[nVoprosa][2][3] )
button4:setLabel( tb[nVoprosa][2][4] )
local j1
for i = #kor, 2, -1 do
j1 = math.random( i )
kor[i], kor[j1] = kor[j1], kor[i]
end
button1.x = kor[1][1]
button1.y = kor[1][2]
button2.x = kor[2][1]
button2.y = kor[2][2]
button3.x = kor[3][1]
button3.y = kor[3][2]
button4.x = kor[4][1]
button4.y = kor[4][2]
end
t = 2
end
end
local function vbn()
t = t - 1
if t == 0 then
scetcikBalpl = scetcikBalpl + 1
balpl.text = scetcikBalpl
scetcikLevel = scetcikLevel + 1
if ( scetcikLevel == 10) then
settings.yesJ = scetcikBal
settings.noJ = scetcikBalpl
settings.procent = (scetcikBal * 10)
saveSettings()
composer.gotoScene( "Level1Score")
else
button1:setEnabled( true )
button2:setEnabled( true )
button3:setEnabled( true )
button4:setEnabled( true )
tapText:setFillColor(255/255, 255/255, 255/255, 1)
tapText.size = 40
nVoprosa = nVoprosa + 1
tapText.text = tb[nVoprosa][1]
button1:setLabel( tb[nVoprosa][2][1] )
button2:setLabel( tb[nVoprosa][2][2] )
button3:setLabel( tb[nVoprosa][2][3] )
button4:setLabel( tb[nVoprosa][2][4] )
local j1
for i = #kor, 2, -1 do
j1 = math.random( i )
kor[i], kor[j1] = kor[j1], kor[i]
end
button1.x = kor[1][1]
button1.y = kor[1][2]
button2.x = kor[2][1]
button2.y = kor[2][2]
button3.x = kor[3][1]
button3.y = kor[3][2]
button4.x = kor[4][1]
button4.y = kor[4][2]
end
t = 2
end
end
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
stop1()
timer.performWithDelay( 300, vb, t )
--vb()
end
end
local function handleButtonEventN( event )
if ( "ended" == event.phase ) then
stop2()
timer.performWithDelay( 300, vbn, t )
--vbn()
end
end
---------------------------------------------------------------------------------------
function scene:create( event )
local sceneGroup = self.view
timer.performWithDelay( 1000, obnovVr, secondL )
tapText = display.newText("", display.contentCenterX, display.contentCenterY - 80, "Lato-Regular.ttf", 40 )
tapText.text = tb[1][1]
button1 = widget.newButton(
{
id = "button1",
label = tb[nVoprosa][2][1],
onEvent = handleButtonEvent,
labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
fontSize = 36,
font = "Lato-Regular.ttf",
emboss = false,
shape = "roundedRect",
width = 120,
height = 60,
cornerRadius = 0,
fillColor = { default={55/255,50/255,47/255,1}, over={31/255,76/255,115/255,1} },
strokeColor = { default={0/255,196/255,253/255,1}, over={0.8,0.8,1,1} },
strokeWidth = 3
}
)
button2 = widget.newButton(
{
id = "button2",
label = tb[nVoprosa][2][2],
onEvent = handleButtonEventN,
labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
fontSize = 36,
font = "Lato-Regular.ttf",
emboss = false,
shape = "roundedRect",
width = 120,
height = 60,
cornerRadius = 0,
fillColor = { default={55/255,50/255,47/255,1}, over={31/255,76/255,115/255,1} },
strokeColor = { default={0/255,196/255,253/255,1}, over={0.8,0.8,1,1} },
strokeWidth = 3
}
)
button3 = widget.newButton(
{
id = "button3",
label = tb[nVoprosa][2][3],
onEvent = handleButtonEventN,
labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
fontSize = 36,
font = "Lato-Regular.ttf",
emboss = false,
shape = "roundedRect",
width = 120,
height = 60,
cornerRadius = 0,
fillColor = { default={55/255,50/255,47/255,1}, over={31/255,76/255,115/255,1} },
strokeColor = { default={0/255,196/255,253/255,1}, over={0.8,0.8,1,1} },
strokeWidth = 3
}
)
button4 = widget.newButton(
{
id = "button4",
label = tb[nVoprosa][2][4],
onEvent = handleButtonEventN,
labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
fontSize = 36,
font = "Lato-Regular.ttf",
emboss = false,
shape = "roundedRect",
width = 120,
height = 60,
cornerRadius = 0,
fillColor = { default={55/255,50/255,47/255,1}, over={31/255,76/255,115/255,1} },
strokeColor = { default={0/255,196/255,253/255,1}, over={0.8,0.8,1,1} },
strokeWidth = 3
}
)
--
button1.x = kor[1][1]
button1.y = kor[1][2]
button2.x = kor[2][1]
button2.y = kor[2][2]
button3.x = kor[3][1]
button3.y = kor[3][2]
button4.x = kor[4][1]
button4.y = kor[4][2]
casi.x = 240
casi.y = 2
yes.x = 40
yes.y = 2
no.x = 140
no.y = 2
bal = display.newText(scetcikBal, 80, 3, "Lato-Regular.ttf", 30 )
balpl = display.newText(scetcikBalpl, 180, 3, "Lato-Regular.ttf", 30 )
vrem = display.newText("20", 290, 3, "Lato-Regular.ttf", 30 )
sceneGroup:insert(bal)
sceneGroup:insert(balpl)
sceneGroup:insert(yes)
sceneGroup:insert(no)
sceneGroup:insert(vrem)
sceneGroup:insert(casi)
sceneGroup:insert(tapText)
sceneGroup:insert(button1)
sceneGroup:insert(button2)
sceneGroup:insert(button3)
sceneGroup:insert(button4)
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
elseif (phase == "did") then
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
elseif (phase == "did") then
composer.removeScene( "level1" )
end
end
function scene:destroy( event )
local sceneGroup = self.view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------
return sceneenter code here
C:\Users\User\Documents\Corona Projects\MATH FOR CHILDREN\level1.lua:207: attempt to call method 'setFillColor' (a nil value)
In line 207 of level1.lua you do this setFillColor() which is not allowed as setFillColor is not a function value but a nil value.
setFillColor is a method of the ShapeObject class. Make sure you're doing using it like this: myShapeObject:setFillColor(myColor)
I'm making a preloader for a large application. Today the error occurred "no such file or directory". This error occurs only on Android device. On the computer(in the simulator) works fine. All file names and directories to lowercase.
Code:
---------------------------------------------
---------------- Прелоадер ------------------
-- Сервис по загрузке текстур, звука --------
---------------------------------------------
TEXTURES = {} -- место в оперативной памяти для текстур
SOUNDS = {} -- место в оперативной памяти для звука
local Preloader = {}
local path = {
animations = "assets/images/animations/",
army_run = "assets/images/animations/army_run/",
area = "assets/images/area/",
access = "assets/images/area/access/",
artefacts = "assets/images/artefacts/",
castles = "assets/images/building/castles/",
mining = "assets/images/building/mining/",
flags = "assets/images/flags/",
interface = "assets/images/interface/",
marker = "assets/images/interface/marker/",
items = "assets/images/items/",
raw = "assets/images/raw/",
}
-- Место для путей к текстурам
Preloader.texture = {}
-- Место для путей к звуку
Preloader.sound = {}
-- Загрузка текстур в оперативную память
Preloader.loadingTextures = function(arr)
TEXTURES[arr.id] = {}
for i = 1, #arr do
local name = string.gsub(arr[i], '.*(.*)/', '')
TEXTURES[arr.id][name] = graphics.newTexture( { type="image", filename = arr[i] } )
TEXTURES[arr.id][name]:preload()
end
end
-- Загрузка звука в оперативную память
Preloader.loadingSounds = function()
for i = 1, #Preloader.sound do
sounds[Preloader.sound[i]] = audio.loadSound( "snd/"..Preloader.sound[i] )
end
end
-- Таймер
Preloader.getTimer = function()
return system.getTimer()
end
-- Окно загрузки
Preloader.screenLoader = nil
Preloader.loaderShow = function()
if(Preloader.screenLoader)then
return false
end
Preloader.screenLoader = display.newGroup()
Preloader.screenLoader.x = _W/2
Preloader.screenLoader.y = _H/2
local screen = display.newRect( 0, 0, _W, _H )
screen:setFillColor( 0, 0, 0 )
Preloader.screenLoader:insert(screen)
local imgLoad = "assets/images/animations/army_run/150.png"
local sheetLoad = graphics.newImageSheet( imgLoad, { width = 224, height = 224, numFrames = 8 } )
local animLoad = display.newSprite( Preloader.screenLoader, sheetLoad, { start = 1, count = 8, time = 800, loopCount=0 } )
animLoad.xScale, animLoad.yScale = _H*.001, _H*.001
animLoad.x, animLoad.y = 0, _H*-.07
animLoad:play()
-- Загрузка в процентах
tfLoader = display.newText( TEXTS.Preloader.loading..": 0%", 0, _H*.08, font, _H*.035 )
tfLoader:setTextColor( 1,1,1)
Preloader.screenLoader:insert(tfLoader)
Preloader.screenLoader.tf = tfLoader
-- Загрузка в этапах
stepLoader = display.newText( TEXTS.Preloader.start_load, 0, _H*.125, font, _H*.022 )
stepLoader:setTextColor( 160/255, 160/255, 160/255 )
Preloader.screenLoader:insert(stepLoader)
Preloader.screenLoader.step = stepLoader
end
-- Создание массивов с путями
Preloader.createPath = function()
for k, v in pairs(path) do
local i = 0
Preloader.texture[k] = { id = k }
for l in lfs.dir(v) do
if ( l ~= "." and l ~= ".." and l ~= "..." ) then
i = i + 1
Preloader.texture[k][i] = v..l
end
end
end
end
-- Запуск прелоадера и контроль процесса загрузки
Preloader.start = function()
-- Создаём шаги для загрузки
local loading_steps = {}
-- Шаг 1 - Загрузка путей
table.insert(loading_steps, function()
Preloader.createPath()
Preloader.screenLoader.step.text = TEXTS.Preloader.path_load..'...'
end)
-- Шаг 2 - Загрузка текстур интерфейса
table.insert(loading_steps, function()
Preloader.loadingTextures(Preloader.texture.interface)
Preloader.loadingTextures(Preloader.texture.marker)
Preloader.screenLoader.step.text = TEXTS.Preloader.interface_load..'...'
end)
-- Шаг 3 - Загрузка анимаций
table.insert(loading_steps, function()
Preloader.loadingTextures(Preloader.texture.animations)
Preloader.loadingTextures(Preloader.texture.army_run)
Preloader.screenLoader.step.text = TEXTS.Preloader.animations_load..'...'
end)
-- Шаг 4 - Создание карты
table.insert(loading_steps, function()
Preloader.loadingTextures(Preloader.texture.area)
Preloader.loadingTextures(Preloader.texture.access)
Preloader.loadingTextures(Preloader.texture.castles)
Preloader.loadingTextures(Preloader.texture.mining)
Preloader.screenLoader.step.text = TEXTS.Preloader.map_load..'...'
end)
-- Шаг 5 - Загрузка ресурсов
table.insert(loading_steps, function()
Preloader.loadingTextures(Preloader.texture.raw)
Preloader.loadingTextures(Preloader.texture.items)
Preloader.loadingTextures(Preloader.texture.artefacts)
Preloader.screenLoader.step.text = TEXTS.Preloader.res_load..'...'
end)
-- Шаг 6 - Загрузка параметров игрока
table.insert(loading_steps, function()
Preloader.loadingTextures(Preloader.texture.flags)
Preloader.screenLoader.step.text = TEXTS.Preloader.res_load..'...'
end)
local loading_steps_max = #loading_steps+1
local st = Preloader.getTimer()
Preloader.loaderShow()
local function mainHandler(e)
if(#loading_steps>0)then
loading_steps[1]()
table.remove(loading_steps, 1)
if(Preloader.screenLoader)then
local loading_p = math.floor((loading_steps_max - #loading_steps)*100/loading_steps_max)
Preloader.screenLoader.tf.text = TEXTS.Preloader.loading..': '..loading_p..'%'
end
return true
end
Preloader.loaderClose()
print('Time load: '..(Preloader.getTimer()-st)..'ms')
Runtime:removeEventListener("enterFrame", mainHandler)
end
Runtime:addEventListener("enterFrame", mainHandler)
end
-- Окончание загрузки
Preloader.loaderClose = function()
if(Preloader.screenLoader)then
if(Preloader.screenLoader.removeSelf)then
Preloader.screenLoader:removeSelf()
end
end
Preloader.screenLoader = nil
-- Переход на стартовую сцену
composer.gotoScene( start_scene, "fade", 0 )
end
-- Сборщик мусора
Preloader.garbage_collector = function()
for key in pairs(TEXTURES) do
for i=1, #TEXTURES[key] do
TEXTURES[key][i]:releaseSelf()
end
end
TEXTURES = {}
end
return Preloader
That's how I show images on stage:
M.dial = display.newImageRect( M.gr, TEXTURES.interface["btn_compas_comp.png"].filename, TEXTURES.interface["btn_compas_comp.png"].baseDir, 272, 272 )
M.dial.x, M.dial.y = X, Y
Thanks in advance friends.
1) All file names and directories to lowercase - I suggest to double-check this because Android filesystem is case sensitive.
2) Also check your build.settings to ensure that excludeFiles section doesn't include any of directories from your code
Edit: Another idea based on corona lfs doc - try following before loading:
local resourcesPath = system.pathForFile( "", system.ResourceDirectory )
-- Change current working directory
local success = lfs.chdir( resourcesPath ) --returns true on success
I guess that lfs doesn't point on resource directory by default. All your assets should be in this directory, but don't try to modify them - For security reasons, this directory is read-only and enforced by the operating system, not by Corona.
Edit 2: Solution that don't rely on current directory
Preloader.createPath = function()
for k, v in pairs(path) do
local i = 0
local pathForDirectory = system.pathForFile(v, system.ResourceDirectory)
Preloader.texture[k] = { id = k }
for l in lfs.dir(pathForDirectory) do
if ( l ~= "." and l ~= ".." and l ~= "..." ) then
i = i + 1
Preloader.texture[k][i] = v..l
end
end
end
end
I am having problems with my Lua. I an making a MOTD for my server using HTML that I am going to host with my website.
I have my frames set up and the according tabs, as seen
But this is my problem
As you exit the MOTD by pressing 'accept', the page set in the code stays up as seen and invades your screen like hell. My code is as follows:
function Welcome ()
MainMenu = vgui.Create( "DFrame" )
MainMenu:SetPos( 350, 100 )
MainMenu:SetSize( 1200, 900 )
MainMenu:SetTitle( "Welcome Menu" )
MainMenu:SetBackgroundBlur( true )
MainMenu:SetVisible( true )
MainMenu:SetDraggable( true )
MainMenu:ShowCloseButton( false )
MainMenu:MakePopup()
PropertySheet = vgui.Create( "DPropertySheet")
PropertySheet:SetParent( MainMenu )
PropertySheet:SetPos( 5, 30 )
PropertySheet:SetSize( 1190, 820 )
local DermaButton = vgui.Create( "DButton", DermaPanel )
DermaButton:SetText( "Agree" )
DermaButton:SetSize( 165, 30 )
DermaButton:SetPos( 590, 860 )
DermaButton:SetParent( MainMenu )
DermaButton.DoClick = function()
MainMenu:Close()
RunConsoleCommand( "say", "I have read and agree with the rules")
end
local DermaButton = vgui.Create( "DButton", DermaPanel )
DermaButton:SetText( "Disagree" )
DermaButton:SetSize( 165, 30 )
DermaButton:SetPos( 420, 860 )
DermaButton:SetParent( MainMenu )
DermaButton.DoClick = function()
MainMenu:Close()
surface.PlaySound( "buttons/button8.wav" )
RunConsoleCommand( "say", "I disagree with the rules, I will now be disconnected.")
RunConsoleCommand( "disconnect" )
end
local TabOne = vgui.Create( "DPanel" )
TabOne:SetVisible( true )
local HTML = vgui.Create("HTML")
HTML:SetPos(50,50)
HTML:SetSize(ScrW() - 100, ScrH() - 100)
HTML:OpenURL("http://www.garrysmod.com")
local TabThree = vgui.Create( "DPanel" )
TabThree:SetVisible( true )
local HTML = vgui.Create("HTML")
HTML:SetPos(50,50)
HTML:SetSize(ScrW() - 100, ScrH() - 100)
HTML:OpenURL("http://www.garrysmod.com")
local TabTwo = vgui.Create( "DPanel" )
TabTwo:SetVisible( true )
local HTML = vgui.Create("HTML")
HTML:SetPos(50,50)
HTML:SetSize(ScrW() - 100, ScrH() - 100)
HTML:OpenURL("http://www.garrysmod.com")
local TabFour = vgui.Create( "DPanel" )
TabThree:SetVisible( true )
local HTML = vgui.Create("HTML")
HTML:SetPos(50,50)
HTML:SetSize(ScrW() - 100, ScrH() - 100)
HTML:OpenURL("http://www.garrysmod.com")
local TabFive = vgui.Create( "DPanel" )
TabThree:SetVisible( true )
local HTML = vgui.Create("HTML")
HTML:SetPos(50,50)
HTML:SetSize(ScrW() - 100, ScrH() - 100)
HTML:OpenURL("http://www.garrysmod.com")
PropertySheet:AddSheet( "Home", TabOne, "gui/silkicons/heart",
false, false, "Welcome to the server!" )
PropertySheet:AddSheet( "Rules", TabTwo, "gui/silkicons/script",
false, false, "Server rules!" )
PropertySheet:AddSheet( "Group", TabThree, "gui/silkicons/group",
false, false, "Group page!" )
PropertySheet:AddSheet( "Ranks", TabFour, "gui/silkicons/flag_blue",
false, false, "Ranks and donations!" )
PropertySheet:AddSheet( "Admins", TabFive, "gui/silkicons/shield",
false, false, "Your admin squad!" )
end
concommand.Add("OpenMotd", Welcome )
If you need to contact me fast, I can be found on Steam, under steamcommunity.com/id/PonyTerrance
This is happening, because you are not closing the HTML object anywhere in the code.
Also remember, that you are creating multiple HTML objects with the same variable name - Either choose an unique variable name for each one or simply create one HTML object and remove the other code passages which are creating HTML objects.
I am trying to spawn a new display.newRect if to old one is < 100 but I'm getting a 'Attempt to compare nil with number'
function hollSpawne(i)
if (i).x < 100 then
hollspawn()
end
end
HollControll = timer.performWithDelay( 1400 , hollSpawne, 0 )
I cant see the error, could someone please explain how to fix this ?
Fullcode :
function pluspoint(i)
score = score + 1
display.remove(i)
end
screenGroup = self.view
holl = {}
hollSpawn = function()
i = display.newRect( 0, 0, math.random(10, 500), 53 )
i.x = display.contentWidth + i.contentWidth + 10
i.y = display.contentHeight - 53/2
i:setFillColor( 1, 0, 0 )
i.name = "hollgameover"
physics.addBody(i, "static", {density=.1, bounce=0.5, friction=.2,filter=playerCollisionFilter } )
trans55 = transition.to(i,{time=2000, x=display.contentWidth - display.contentWidth - i.contentWidth/2 - 20, onComplete=pluspoint, transition=easing.OutExpo } )
holl[#holl+1] = i
screenGroup:insert(i)
end
timereholl = timer.performWithDelay( 100 , hollSpawn, 1 )
function hollSpawne(i)
if (i).x < 100 then
hollspawn()
end
end
HollControll = timer.performWithDelay( 1400 , hollSpawne, 0 )
-
-
new test still not working
screenGroup = self.view
holl = {}
hollSpawn = function()
i = display.newRect( 0, 0, math.random(10, 500), 53 )
i.x = display.contentWidth + i.contentWidth + 10
i.y = display.contentHeight - 53/2
i:setFillColor( 1, 0, 0 )
i.name = "hollgameover"
physics.addBody(i, "static", {density=.1, bounce=0.5, friction=.2,filter=playerCollisionFilter } )
trans55 = transition.to(i,{time=2000, x=display.contentWidth - display.contentWidth - i.contentWidth/2 - 20, onComplete=pluspoint, transition=easing.OutExpo } )
holl[#holl+1] = i
screenGroup:insert(i)
end
timereholl = timer.performWithDelay( 100 , hollSpawn, 1 )
function hollSpawne(event)
if (i).x < 100 then
hollSpawn()
end
end
HollControll = timer.performWithDelay( 1400 , hollSpawne, 0 )
Your timer calls hollSpawne with no arguments, but in function you use 'i' parameter.
Try this one:
local function hollSpawne(i)
if i.x < 100 then
hollspawn()
end
end
HollControll = timer.performWithDelay( 1400 , function()
hollSpawne(my_i_value)
end, 0 )
The timer calls the listener with event as argument so i is an event. Since i is a global you can just have the arg be event:
function hollSpawne(event)
if (i).x < 100 then
hollSpawn()
end
end
Note that I use hollSpawn not hollspawn as I think this is a typo that will cause additional bug.
Sidenote on style: not sure why you need () around i, un-Lua'ish. Also you probably should declare i local to your module:
local i
screenGroup = self.view
holl = {}
hollSpawn = function()
i = display.newRect( 0, 0, math.random(10, 500), 53 )
...
I ran this code and it gave me an error attempt to index global 'self' (a nil value), in this scene i'm creating the Question1 of the game, inside which includes creating cannon, balloons and other game elements. I checked but i'm not sure whats wrong here.
function scene.createScene()
local group = self.view ---line 27 where i got the error
scoreText = display.newText( "0", 0, 0, globals.font.bold, 32 )
scoreText.x = display.contentCenterX
scoreText.y = 32
group:insert( scoreText )
background = display.newImage( "bkg_clouds.png")
group:insert(background)
background.x = 240
background.y = 195
questionText = display.newText('a', display.contentCenterX, display.contentWidth/4, native.systemFont, 40)
group:insert(questionText)
infoBar = display.newImage ("infoBar.png")
group:insert(infoBar)
background.x = 200
background.y = 100
restartBtn = display.newImage ("restartBtn.png")
group:insert(restartBtn)
background.x = 470
background.y = 300
cannon = display.newImage ("cannon.png")
group:insert(cannon)
background.x = 10
background.y = 270
cannon.anchorX = 0.5
cannon.anchorY = 0.5
restartBtn.isVisible = true
function createBalloons(a, b)
for i = 1, a do
for j = 1, b do
local balloon = display.newImage ('balloon_fat_red.png', 465+ (i * 30), 80 + (j * 50))
balloon.balloonText1 = display.newText(hiragana_array[x+1], 495, 125)
balloon.balloonText2 = display.newText(hiragana_array[x+2], 495, 175)
balloon.balloonText3 = display.newText(hiragana_array[x+3], 495, 225)
balloon.balloonText1:setFillColor( 1,1, 0 )
balloon.balloonText2:setFillColor( 1,1, 0 )
balloon.balloonText3:setFillColor( 1,1, 0 )
balloon.name = 'balloon'
physics.addBody(balloon)
balloon.bodyType = 'static'
table.insert(balloons, balloon)
end
end
target.text = #balloons
end
function cannonCharge:touch(e)
if(e.phase == 'began') then
impulse = 0
cannon.isVisible = true
Runtime:addEventListener('enterFrame', charge)
end
end
function charge()
local degreesPerFrame = 1
cannon.rotation = cannon.rotation - degreesPerFrame
impulse=impulse-0.2
if(cannon.rotation < -46) then
cannon.rotation = -46
impulse = -3.2
end
end
function shot:touch(e)
if(e.phase == 'ended') then
Runtime:removeEventListener('enterFrame', charge)
cannon.isVisible = false
cannon.rotation = 0
local cannonBall = display.newImage('cannon ball.png', 84, 220)
physics.addBody(cannonBall, {density = 1, friction = 0, bounce = 0})
group:insert(cannonBall)
-- Shoot cannon ball
cannonBall:applyLinearImpulse(dir, impulse, cannonBall.x, cannonBall.y )
--Collision listener
cannonBall:addEventListener ('collision', ballCollision)
end
end
function ballCollision(e)
if (e.other.name == 'balloon') then
scene.updateScore()
e.target:removeSelf()
print ('remove balloon text')
e.other:removeSelf()
audio.play(pop)
end
end
cannonBall:applyLinearImpulse(dir, impulse, cannonBall.x, cannonBall.y )
--Collision listener
cannonBall:addEventListener ('collision', ballCollision)
scene.view:insert( ballCollision )
end
You probably need function scene:createScene(). Note the colon instead of the dot in your original code.
Your function should be like this.
function scene:createScene( event )
local group = self.view
-----------------------------------------------------------------------------
-- CREATE display objects and add them to 'group' here.
-- Example use-case: Restore 'group' from previously saved state.
-----------------------------------------------------------------------------
end
Here is the reference:
http://docs.coronalabs.com/api/library/storyboard/