Cuberite Forum
callback DoWithBlockEntityAt why not work - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: callback DoWithBlockEntityAt why not work (/thread-2502.html)

Pages: 1 2


callback DoWithBlockEntityAt why not work - as123456 - 08-29-2016

function OnPlayerRightClick(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)
  local world=Player:GetWorld()
  world:DoWithBlockEntityAt(BlockX, BlockY, BlockZ,
    function  (a_BlockEntity)
      LOG(a_BlockEntity:GetBlockType())
    end
  )
  LOG("End")
  return false
end

(Edited by xoft to add formatting)


RE: callback DoWithBlockEntityAt why not work - xoft - 08-29-2016

Hello, welcome to the forum.

What exactly is the behavior you see and what is the behavior you were expecting? (In other words, what does "not work" mean?)


RE: callback DoWithBlockEntityAt why not work - as123456 - 08-30-2016

(08-29-2016, 10:56 PM)xoft Wrote: Hello, welcome to the forum.

What exactly is the behavior you see and what is the behavior you were expecting? (In other words, what does "not work" mean?)

Callback is not executed


RE: callback DoWithBlockEntityAt why not work - DrMasik - 08-30-2016

(08-30-2016, 01:22 AM)as123456 Wrote:
(08-29-2016, 10:56 PM)xoft Wrote: Hello, welcome to the forum.

What exactly is the behavior you see and what is the behavior you were expecting? (In other words, what does "not work" mean?)

Callback is not executed

You must register hook before use

cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, MyOnPlayerRightClick);

And rename your function OnPlayerRightClick to MyOnPlayerRightClick


RE: callback DoWithBlockEntityAt why not work - as123456 - 08-30-2016

(08-30-2016, 01:23 AM)DrMasik Wrote:
(08-30-2016, 01:22 AM)as123456 Wrote:
(08-29-2016, 10:56 PM)xoft Wrote: Hello, welcome to the forum.

What exactly is the behavior you see and what is the behavior you were expecting? (In other words, what does "not work" mean?)

Callback is not executed

You must register hook before use
I Register!


RE: callback DoWithBlockEntityAt why not work - DrMasik - 08-30-2016

(08-30-2016, 01:27 AM)as123456 Wrote: I Register!

Show all your code


RE: callback DoWithBlockEntityAt why not work - as123456 - 08-30-2016

Code:
PLUGIN = {}    -- Reference to own plugin object
CHEST_WIDTH = 9
HANDY_VERSION = 1

function Initialize(Plugin)
PLUGIN = Plugin
PLUGIN:SetName("Reap")
PLUGIN:SetVersion(HANDY_VERSION)

cPluginManager:AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage);

--cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY, OnPlayerRightClickingEntity);

cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, OnPlayerRightClick);

-- Registers the commands found in Info.lua
--RegisterPluginInfoCommands()    

LOG("Initialized " .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion())
return true
end

function OnDisable()
LOG(PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. " is shutting down...")
end
function OnPlayerRightClick(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)

local world=Player:GetWorld()

world:DoWithBlockEntityAt(BlockX, BlockY, BlockZ,
function  (a_BlockEntity)
LOG(a_BlockEntity:GetBlockType())
end

)
LOG("End")
return false
end



RE: callback DoWithBlockEntityAt why not work - DrMasik - 08-30-2016

(08-30-2016, 01:30 AM)as123456 Wrote:
Code:
PLUGIN = {}    -- Reference to own plugin object
CHEST_WIDTH = 9
HANDY_VERSION = 1

function Initialize(Plugin)
PLUGIN = Plugin
PLUGIN:SetName("Reap")
PLUGIN:SetVersion(HANDY_VERSION)

cPluginManager:AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage);

--cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY, OnPlayerRightClickingEntity);

cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, OnPlayerRightClick);

-- Registers the commands found in Info.lua
--RegisterPluginInfoCommands()    

LOG("Initialized " .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion())
return true
end

function OnDisable()
LOG(PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. " is shutting down...")
end
function OnPlayerRightClick(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)

local world=Player:GetWorld()

world:DoWithBlockEntityAt(BlockX, BlockY, BlockZ,
function  (a_BlockEntity)
LOG(a_BlockEntity:GetBlockType())
end

)
LOG("End")
return false
end

Replace ":" to "."
cPluginManager:AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage); => cPluginManager.AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage);

It's not C++ Wink


RE: callback DoWithBlockEntityAt why not work - as123456 - 08-30-2016

(08-30-2016, 01:38 AM)DrMasik Wrote:
(08-30-2016, 01:30 AM)as123456 Wrote:
Code:
PLUGIN = {}    -- Reference to own plugin object
CHEST_WIDTH = 9
HANDY_VERSION = 1

function Initialize(Plugin)
PLUGIN = Plugin
PLUGIN:SetName("Reap")
PLUGIN:SetVersion(HANDY_VERSION)

cPluginManager:AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage);

--cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY, OnPlayerRightClickingEntity);

cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, OnPlayerRightClick);

-- Registers the commands found in Info.lua
--RegisterPluginInfoCommands()    

LOG("Initialized " .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion())
return true
end

function OnDisable()
LOG(PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. " is shutting down...")
end
function OnPlayerRightClick(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)

local world=Player:GetWorld()

world:DoWithBlockEntityAt(BlockX, BlockY, BlockZ,
function  (a_BlockEntity)
LOG(a_BlockEntity:GetBlockType())
end

)
LOG("End")
return false
end

Replace ":" to "."
cPluginManager:AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage); => cPluginManager.AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage);

It's not C++ Wink



RE: callback DoWithBlockEntityAt why not work - as123456 - 08-30-2016

Not the reason!