This code throws an error:
Code: Select all
local o = findEntity("someItemIDthatIsEquipable")
o.item:addConnector("onEquipItem", "myScriptEntity", "mySuperAwesomeFunctionWhenEquipping")
Code: Select all
local o = findEntity("someItemIDthatIsEquipable")
o.item:addConnector("onEquipItem", "myScriptEntity", "mySuperAwesomeFunctionWhenEquipping")
Code: Select all
defineObject{
baseObject = "base_item",
name = "someItemWithEvents",
components = {
{
class = "Item",
onEquipItem = function(self, champion, slot) print(self, champion, slot) end,
onUnequipItem = function(self, champion, slot) print(self, champion, slot) end,
}
}
}
Code: Select all
function addHooksToComponents(componentName,hooks,override)
for name,def in pairs(defines) do
local c = findComponent(def,componentName)
if c then
for hookName,method in pairs(hooks) do
if override or c[hookName] == nil then
c[hookName] = method
end
end
defineObject(def);
end
end
end
Code: Select all
local hooks = {
onEquipItem = function(self, champion, slot)
your.script.onEquipItem(self, champion, slot)
end,
onUnequipItem = function(self, champion, slot)
your.script.onUnequipItem(self, champion, slot)
end
}
addHooksToComponents('item',hooks)
When is this code being called?NutJob wrote:This thread is dedicated to code you think should work but it won't or throws an error and is potentially a bug. This is not for musing code theory and how to use certain aspects of the API.
This code throws an error:
Code: Select all
local o = findEntity("someItemIDthatIsEquipable") o.item:addConnector("onEquipItem", "myScriptEntity", "mySuperAwesomeFunctionWhenEquipping")
Code: Select all
function myTestSpawn()
local o = spawn("rope", party.level, party.x, party.y, 0, party.elevation)
o.item:addConnector("onEquipItem", "lib", "aaa")
o.item:addConnector("onUnequipItem", "lib", "bbb")
end
function aaa()
print("A")
end
function bbb()
print("B")
end