Hi everyone,
I’m developing a 2D action game using the Playdate SDK, and my project is organized into multiple modules. One of my modules, Effect_MaxChargeSprite.lua
, is responsible for handling a special charge-effect animation (for a “drill attack” at maximum charge). However, I’m encountering a problem where the init()
function in this module is never being called—even though I can see that the file is being loaded correctly.
Problem Details:
- When the project loads, I see the message
"Effect_MaxChargeSprite.lua loaded!"
in the console, which confirms that the file is indeed being imported. - However, none of the debug prints I’ve placed at the beginning of the
init()
function (for example,"Effect_MaxChargeSprite:init() START"
or a print showing the image table length) ever appear in the log. - As a result, the effect instance is never properly created, and its animation never runs.
- Other modules (like Player, PlayerEffect, Weapon_Spear01, etc.) seem to be working as intended. I’m also ensuring that the effect instance is being preserved (I store it in a global variable
_G.debugChargeEffect
and in the effect manager) so that it's not garbage-collected. - I’ve double-checked the call stack from the module that instantiates the effect (in
PlayerAttack:showMaxChargeEffect()
), and I adjusted the parameter order (e.g., ensuring fixed coordinates are defined before they are passed to the constructor). Still, theinit()
method inEffect_MaxChargeSprite.lua
is never executed.
Environment:
- Playdate SDK (latest version)
- Using Lua with a standard class system (e.g.,
class('Effect_MaxChargeSprite').extends(gfx.sprite)
) - Running on Windows
What I’ve Tried:
- File Load Confirmation: I added a debug print at the very top of
Effect_MaxChargeSprite.lua
:
lua
print("Effect_MaxChargeSprite.lua loaded!")
This prints correctly when I load the game.
2. Debug Prints in init(): I placed prints at the very start and end of the init()
function:
lua
function Effect_MaxChargeSprite:init(initialImage, imageTable, x, y, frameDelay, loop, duration)
print("Effect_MaxChargeSprite:init() START")
assert(imageTable, "Effect_MaxChargeSprite: imageTable is nil!")
...
print("Effect_MaxChargeSprite:init - ImageTable length:", self.imageTable:getLength())
...
print("Effect_MaxChargeSprite:init() END")
end
None of these messages appear in the log.
3. Reference Preservation: In PlayerAttack:showMaxChargeEffect()
, I assign the created effect instance to both a field in my PlayerEffect
module and a global variable (_G.debugChargeEffect
) to prevent it from being garbage-collected:
lua
local fixedX = 50
local fixedY = 210
self.player.effectManager.chargeEffectSprite = Effect_MaxChargeSprite:new(
initialImage,
weapon.maxChargeEffectImageTable,
fixedX,
fixedY,
100,
false,
500
)
_G.debugChargeEffect = self.player.effectManager.chargeEffectSprite
print("Global debugChargeEffect:", _G.debugChargeEffect)
print("Effect created at fixed position:", fixedX, fixedY)
Later logs show that _G.debugChargeEffect
is a valid sprite instance with a proper parent (getParent
exists). But still, the init()
debug prints are never seen.
4. Global Update Loop: I verified that playdate.update()
calls playdate.graphics.sprite.update()
properly, so all sprite update and draw methods should be executed normally.
My Question: Why is the init()
method of Effect_MaxChargeSprite.lua
never being called? Could this be due to Lua module caching, garbage collection, or some other instantiation timing issue? Has anyone encountered a similar problem with Playdate’s module instantiation?
Any insights or suggestions would be greatly appreciated!
Thank you in advance for your help!