So I’m trying to create an imagesheet and I’ve done this before with no problems but now I’m getting the bug “attempt to index global ‘graphics’ (a nil value)”
What did I do? [import]uid: 178013 topic_id: 35734 reply_id: 335734[/import]
Can you throw up some code? It would be easier to troubleshoot. [import]uid: 135394 topic_id: 35734 reply_id: 142094[/import]
If graphics is showing up nil, it means you may have overwritten the graphics library with a variable named “graphics”. Check to see if you have a variable with that name somewhere… [import]uid: 41884 topic_id: 35734 reply_id: 142100[/import]
Here are the first 50 lines up until the bug. I only reference graphics one other time in the project and thats when I make the other imagesheet.
[blockcode]module(…)
function getParticleData()
– Initialize and fetch default particle values
local SheetInfo =
{
– WIDTH AND HEIGHT OF THE ENTIRE SHEET
sheetContentWidth = 512,
sheetContentHeight = 512,
– FRAMES: (ALL PARAMS BELOW ARE REQUIRED FOR EACH FRAME)
frames =
{
– IMAGE 1
{ x = 0, y = 0, width = 125, height = 125 },
– IMAGE 2
{ x = 128, y = 0, width = 125, height = 125 },
– IMAGE 3
{ x = 256, y = 0, width = 125, height = 125 },
– IMAGE 4
{ x = 384, y = 0, width = 125, height = 125 },
{ x = 0, y = 128, width = 125, height = 125 },
{ x = 128, y = 128, width = 125, height = 125 },
{ x = 256, y = 128, width = 125, height = 125 },
{ x = 384, y = 128, width = 125, height = 125 },
{ x = 0, y = 256, width = 125, height = 125 },
{ x = 128, y = 256, width = 125, height = 125 },
{ x = 256, y = 256, width = 125, height = 125 },
{ x = 384, y = 256, width = 125, height = 125 },
{ x = 0, y = 384, width = 125, height = 125 },
{ x = 128, y = 384, width = 125, height = 125 },
{ x = 256, y = 384, width = 125, height = 125 },
{ x = 384, y = 384, width = 125, height = 125 },
}
}
local AnimationInfo =
{
name = “Explosion”,
start = 1,
count = 16,
time = 1500,
loopCount = 0,
loopDirection = “forward”,
}
– LOAD THE IMAGE SHEET:
local ExplosionImageSheet = graphics.newImageSheet( “ExplosionAnim.png”, SheetInfo);
[blockcode] [import]uid: 178013 topic_id: 35734 reply_id: 142189[/import]
I don’t notice anything particularly wrong but it’s hard to tell with such a small chunk of the code. (Also, what’s the “module(…)” bit?) [import]uid: 41884 topic_id: 35734 reply_id: 142255[/import]
I’m not sure what module(…) is. I’m working off someone else’s codebase, I removed it but now I get the error: "Particle.lua:13: attempt to index local ‘pSheet’ (a boolean value)
Heres the function that calls particleSheet:
[blockcode]
function Init(particleSheet)
local pSheet = require(particleSheet)
local pData = pSheet.getParticleData() --Line 13
local eData = pSheet.getEmitterData()
for i = 1, pData.numOfParticles, 1 do
CreateParticle(pData.particles[i])
particleTypes[i] = pData.particles[i]
end
for j = 1, eData.numOfEmitters, 1 do
emitterTypes[j] = eData.emitters[j]
end
eData = nil
pData = nil
pSheet = nil
end [import]uid: 178013 topic_id: 35734 reply_id: 142264[/import]
that module bit is the old way that Corona allowed external modules to be called from within another .lua module. The particle emitter you’re using is being called from that older module. Nothing wrong with it in and of itself, but there are more recent particle emitters that don’t use the out-dated “module” format. You could also make your own, like so:
[lua]
local function testObjBurst()
local testObjRnd = math.random
local function DestroyPop(Obj)
display.remove(Obj)
Obj = nil
end
timer.performWithDelay(10, function()
local function createStars()
timer.performWithDelay(100, function()
testObj = display.newRect(0,0,64,64)
physics.addBody( testObj, “dynamic”,{ density = 3.0, isSensor=true } )
testObj:applyForce(1*(testObjRnd(-550,550)),-800, testObj.x*(testObjRnd(1,10)), testObj.y)
testObj:applyTorque(5*testObjRnd(5,10))
testObj.x = testObjalpha.x
testObj.y = testObjalpha.y-45
transition.to(testObj, {time=starTime, onComplete=DestroyPop})
transition.to(testObjalpha, {time=500, alpha = 1})
return testObj
end, 5)
end
createStars()
end, 1)
end
[/lua]
Your mileage may vary. As far as your graphics error is concerned, I’m going to venture a guess and say the issue may like with the particle emitter you’re using. Below are two I found:
http://developer.coronalabs.com/code/simple-particle-emitter-and-fireworks-show
http://developer.coronalabs.com/code/cbeffects
What exactly are you attempting to accomplish? It might assist in resolving your issue.
[import]uid: 135394 topic_id: 35734 reply_id: 142265[/import]
I’m guessing the graphics error is caused by the module(…) call. Right now all I’m doing is loading the data in. This is all before any actual particle or emitter code. The Second code block I posted is the function that loads in the module and that first code block is the code up to the bug (The rest of the code is the functions that return the particle and emitter tables) [import]uid: 178013 topic_id: 35734 reply_id: 142268[/import]
I noted some mistakes in my code because I wrote it too quickly to check. Sorry!
[lua]
local function testObjBurst()
local testObjRnd = math.random
local function DestroyPop(Obj)
display.remove(Obj)
Obj = nil
end
timer.performWithDelay(10, function()
local function createStars()
timer.performWithDelay(100, function()
testObj = display.newRect(0,0,64,64)
physics.addBody( testObj, “dynamic”,{ density = 3.0, isSensor=true } )
testObj:applyForce(1*(testObjRnd(-550,550)),-800, testObj.x*(testObjRnd(1,10)), testObj.y)
testObj:applyTorque(5*testObjRnd(5,10))
testObj.x = 100
testObj.y = 200
group:insert(testObj)
transition.to(testObj, {time=1500, onComplete=DestroyPop})
return testObj
end, 5)
end
createStars()
end, 1)
end
testObjBurst()
[/lua] [import]uid: 135394 topic_id: 35734 reply_id: 142391[/import]
Can you throw up some code? It would be easier to troubleshoot. [import]uid: 135394 topic_id: 35734 reply_id: 142094[/import]
If graphics is showing up nil, it means you may have overwritten the graphics library with a variable named “graphics”. Check to see if you have a variable with that name somewhere… [import]uid: 41884 topic_id: 35734 reply_id: 142100[/import]
Here are the first 50 lines up until the bug. I only reference graphics one other time in the project and thats when I make the other imagesheet.
[blockcode]module(…)
function getParticleData()
– Initialize and fetch default particle values
local SheetInfo =
{
– WIDTH AND HEIGHT OF THE ENTIRE SHEET
sheetContentWidth = 512,
sheetContentHeight = 512,
– FRAMES: (ALL PARAMS BELOW ARE REQUIRED FOR EACH FRAME)
frames =
{
– IMAGE 1
{ x = 0, y = 0, width = 125, height = 125 },
– IMAGE 2
{ x = 128, y = 0, width = 125, height = 125 },
– IMAGE 3
{ x = 256, y = 0, width = 125, height = 125 },
– IMAGE 4
{ x = 384, y = 0, width = 125, height = 125 },
{ x = 0, y = 128, width = 125, height = 125 },
{ x = 128, y = 128, width = 125, height = 125 },
{ x = 256, y = 128, width = 125, height = 125 },
{ x = 384, y = 128, width = 125, height = 125 },
{ x = 0, y = 256, width = 125, height = 125 },
{ x = 128, y = 256, width = 125, height = 125 },
{ x = 256, y = 256, width = 125, height = 125 },
{ x = 384, y = 256, width = 125, height = 125 },
{ x = 0, y = 384, width = 125, height = 125 },
{ x = 128, y = 384, width = 125, height = 125 },
{ x = 256, y = 384, width = 125, height = 125 },
{ x = 384, y = 384, width = 125, height = 125 },
}
}
local AnimationInfo =
{
name = “Explosion”,
start = 1,
count = 16,
time = 1500,
loopCount = 0,
loopDirection = “forward”,
}
– LOAD THE IMAGE SHEET:
local ExplosionImageSheet = graphics.newImageSheet( “ExplosionAnim.png”, SheetInfo);
[blockcode] [import]uid: 178013 topic_id: 35734 reply_id: 142189[/import]
I don’t notice anything particularly wrong but it’s hard to tell with such a small chunk of the code. (Also, what’s the “module(…)” bit?) [import]uid: 41884 topic_id: 35734 reply_id: 142255[/import]
I’m not sure what module(…) is. I’m working off someone else’s codebase, I removed it but now I get the error: "Particle.lua:13: attempt to index local ‘pSheet’ (a boolean value)
Heres the function that calls particleSheet:
[blockcode]
function Init(particleSheet)
local pSheet = require(particleSheet)
local pData = pSheet.getParticleData() --Line 13
local eData = pSheet.getEmitterData()
for i = 1, pData.numOfParticles, 1 do
CreateParticle(pData.particles[i])
particleTypes[i] = pData.particles[i]
end
for j = 1, eData.numOfEmitters, 1 do
emitterTypes[j] = eData.emitters[j]
end
eData = nil
pData = nil
pSheet = nil
end [import]uid: 178013 topic_id: 35734 reply_id: 142264[/import]
that module bit is the old way that Corona allowed external modules to be called from within another .lua module. The particle emitter you’re using is being called from that older module. Nothing wrong with it in and of itself, but there are more recent particle emitters that don’t use the out-dated “module” format. You could also make your own, like so:
[lua]
local function testObjBurst()
local testObjRnd = math.random
local function DestroyPop(Obj)
display.remove(Obj)
Obj = nil
end
timer.performWithDelay(10, function()
local function createStars()
timer.performWithDelay(100, function()
testObj = display.newRect(0,0,64,64)
physics.addBody( testObj, “dynamic”,{ density = 3.0, isSensor=true } )
testObj:applyForce(1*(testObjRnd(-550,550)),-800, testObj.x*(testObjRnd(1,10)), testObj.y)
testObj:applyTorque(5*testObjRnd(5,10))
testObj.x = testObjalpha.x
testObj.y = testObjalpha.y-45
transition.to(testObj, {time=starTime, onComplete=DestroyPop})
transition.to(testObjalpha, {time=500, alpha = 1})
return testObj
end, 5)
end
createStars()
end, 1)
end
[/lua]
Your mileage may vary. As far as your graphics error is concerned, I’m going to venture a guess and say the issue may like with the particle emitter you’re using. Below are two I found:
http://developer.coronalabs.com/code/simple-particle-emitter-and-fireworks-show
http://developer.coronalabs.com/code/cbeffects
What exactly are you attempting to accomplish? It might assist in resolving your issue.
[import]uid: 135394 topic_id: 35734 reply_id: 142265[/import]
I’m guessing the graphics error is caused by the module(…) call. Right now all I’m doing is loading the data in. This is all before any actual particle or emitter code. The Second code block I posted is the function that loads in the module and that first code block is the code up to the bug (The rest of the code is the functions that return the particle and emitter tables) [import]uid: 178013 topic_id: 35734 reply_id: 142268[/import]
I noted some mistakes in my code because I wrote it too quickly to check. Sorry!
[lua]
local function testObjBurst()
local testObjRnd = math.random
local function DestroyPop(Obj)
display.remove(Obj)
Obj = nil
end
timer.performWithDelay(10, function()
local function createStars()
timer.performWithDelay(100, function()
testObj = display.newRect(0,0,64,64)
physics.addBody( testObj, “dynamic”,{ density = 3.0, isSensor=true } )
testObj:applyForce(1*(testObjRnd(-550,550)),-800, testObj.x*(testObjRnd(1,10)), testObj.y)
testObj:applyTorque(5*testObjRnd(5,10))
testObj.x = 100
testObj.y = 200
group:insert(testObj)
transition.to(testObj, {time=1500, onComplete=DestroyPop})
return testObj
end, 5)
end
createStars()
end, 1)
end
testObjBurst()
[/lua] [import]uid: 135394 topic_id: 35734 reply_id: 142391[/import]