transition.blink() for a certain period of time

Code :

  elseif (event.phase == “began” and event.other.myName == “death”) then
      event.other : removeSelf()
      event.other = nil

            --transition.blink( myAnimation, { time=1000 } )
            --myAnimation.alpha = 0.3;
            --transition.to(myAnimation, {alpha=1, time=500})

            myAnimation.trans = transition.blink(myAnimation,{time=500})
            local function killBlink()
                transition.cancel(myAnimation.trans)
                display.remove(myAnimation)
                myAnimation=nil
            end
            timer.performWithDelay(2000, killBlink)

At the end of the transition time I am getting this error :

11:49:47.582  ERROR: Runtime error
11:49:47.582  C:\Users\sht\Desktop\IndieG\default\Illanias Fate\main.lua:253: attempt to index global ‘myAnimation’ (a nil value)
11:49:47.582  stack traceback:
11:49:47.582      C:\Users\sht\Desktop\IndieG\default\Illanias Fate\main.lua:253: in function ‘?’
11:49:47.582      ?: in function <?:190>
 

Why is there a nil value error? How to fix this issue?

That’s not really enough to start efficiently debugging your problem.

“attempt to index global ‘myAnimation’ (a nil value)” means that either ‘myAnimation’ does not exist or there could be some missing or invalid variables in it. Since you are trying to transition it, I presume it is a display object? Have you made sure that the object has been created before you try to transition it? If it isn’t a display object, it could crash because it isn’t a table.

I expect that others would also need more information to properly address this issue.

_G.sheetData2 = { width=64, height=64, numFrames=273, sheetContentWidth=832, sheetContentHeight=1344 }
_G.sheet2 = graphics.newImageSheet( “Character/GameChar.png”, sheetData2 )
_G.sequenceData2 = {
                                  { name=“rightrun1”, sheet=sheet2, start=144, count= 9, time=500, loopCount=0 },
                                  { name=“leftrun1”, sheet=sheet2, start=118, count=9, time=500, loopCount=0 },
                                  { name=“rightstand1”, frame={146}, start=146, count=1} ,
                                  { name=“leftstand1”, frame={120}, start=120, count=1},
                                  { name=“uprun1”, sheet=sheet2, start=105, count=9, time=500, loopCount=0 },
                                  { name=“upstand1”,frame={106}, start=106, count=1},
                                  { name=“downrun1”, sheet=sheet2, start=131, count=9, time=500, loopCount=0 },
                                  { name=“downstand1”,frame={131}, start=131, count=1}
                                  }

_G.myAnimation = display.newSprite( sheet2, sequenceData2 )
 

It is a display object and has been declared at the top of the main.lua file

The console states that the crash occurs on line #253. Which one of those lines is it? You should use the code tool on the forums to paste code so that it’s formatting doesn’t break and others can more easily see the line numbers (which would be important here).

Thanks for the tip

I did not know there is a code tool on the forums! Will try to figure it out.

I’d love to try to help you out, but I’d need to know exactly which of those lines results in the crash. Also, if I (or other forum users) cannot replicate your error from your code, as we cannot run it, then the debugging process is only guessing.

On another topic, I would personally recommend using local variables whenever possible as local variables tend to have increased performance over globals. I don’t really work with globals for this very reason, unless absolutely necessary, so I can’t exclude the possibility that your use of globals results in the error.

The code tool is the blue <> button in the row with Bold, Italic etc. Click it and paste your code into the window that pops up. You can optionally add a starting line number if it’s important that we see the line numbers.

Rob

That’s not really enough to start efficiently debugging your problem.

“attempt to index global ‘myAnimation’ (a nil value)” means that either ‘myAnimation’ does not exist or there could be some missing or invalid variables in it. Since you are trying to transition it, I presume it is a display object? Have you made sure that the object has been created before you try to transition it? If it isn’t a display object, it could crash because it isn’t a table.

I expect that others would also need more information to properly address this issue.

_G.sheetData2 = { width=64, height=64, numFrames=273, sheetContentWidth=832, sheetContentHeight=1344 }
_G.sheet2 = graphics.newImageSheet( “Character/GameChar.png”, sheetData2 )
_G.sequenceData2 = {
                                  { name=“rightrun1”, sheet=sheet2, start=144, count= 9, time=500, loopCount=0 },
                                  { name=“leftrun1”, sheet=sheet2, start=118, count=9, time=500, loopCount=0 },
                                  { name=“rightstand1”, frame={146}, start=146, count=1} ,
                                  { name=“leftstand1”, frame={120}, start=120, count=1},
                                  { name=“uprun1”, sheet=sheet2, start=105, count=9, time=500, loopCount=0 },
                                  { name=“upstand1”,frame={106}, start=106, count=1},
                                  { name=“downrun1”, sheet=sheet2, start=131, count=9, time=500, loopCount=0 },
                                  { name=“downstand1”,frame={131}, start=131, count=1}
                                  }

_G.myAnimation = display.newSprite( sheet2, sequenceData2 )
 

It is a display object and has been declared at the top of the main.lua file

The console states that the crash occurs on line #253. Which one of those lines is it? You should use the code tool on the forums to paste code so that it’s formatting doesn’t break and others can more easily see the line numbers (which would be important here).

Thanks for the tip

I did not know there is a code tool on the forums! Will try to figure it out.

I’d love to try to help you out, but I’d need to know exactly which of those lines results in the crash. Also, if I (or other forum users) cannot replicate your error from your code, as we cannot run it, then the debugging process is only guessing.

On another topic, I would personally recommend using local variables whenever possible as local variables tend to have increased performance over globals. I don’t really work with globals for this very reason, unless absolutely necessary, so I can’t exclude the possibility that your use of globals results in the error.

The code tool is the blue <> button in the row with Bold, Italic etc. Click it and paste your code into the window that pops up. You can optionally add a starting line number if it’s important that we see the line numbers.

Rob