The problem that I am having is that the two variables that hold the number of times the block has been hit and the initial positon of the block seem to be shared between all other blocks with the same ID. How can I make it so that every block has its own unique version of these variables?
Also, a gif to help illustrate the problem, top left number shows the "hits" variable:
Here's the block's code:
Code: Select all
local blockManager = require("blockManager")
local customBlock = {}
local blockID = BLOCK_ID
local customBlockSettings = {
id = blockID,
frames = 1,
bumpable = true,
}
blockManager.setBlockSettings(customBlockSettings)
local initialY
local hits = 0
local hitEffect = Graphics.loadImage(Misc.resolveFile("test\\block-751effect.png"))
function customBlock.onInitAPI()
blockManager.registerEvent(blockID, customBlock, "onTickEndBlock")
registerEvent(customBlock, "onBlockHit")
end
function customBlock.onTickEndBlock(v)
if v.isHidden or v:mem(0x5A, FIELD_BOOL) then return end
local data = v.data
if hits > 0 then
for i = 0,hits do
Graphics.drawImageToScene(hitEffect,v.x,initialY+(i*-32))
end
end
if hits == 5 then
v.y = initialY
hits = 0
end
end
function customBlock.onBlockHit(eventObject, v, fromUpper, playerOrNil)
if initialY == nil then initialY = v.y end
if hits < 5 then
v.y = v.y - 32
hits = hits + 1
end
end
return customBlock