When a connector is triggered, it checks the component's parent's map in some way. I don't know why it does this, but it does. This means that a connector triggering on a component belonging to an object that is not on a map - such as an item in a champion's inventory, on the mouse, or inside a container - will cause the Lua error you discovered.
If you want to use connectors on items, the easiest way is definitely to use the scripting framework. But
be careful about function ownership. In particular, you should only reference the global environment (and any arguments you receive) in your hook functions.
This is because saving/reloading with a function that is referenced from multiple places can change the environment of the function. For example I created a test dungeon with two script entities named "cow" and "goat". I placed "goat" to the northwest of "cow". Here is the source for "cow":
Code: Select all
ANIMAL = "Cow"
function test()
print(ANIMAL)
end
And the source for "goat":
Code: Select all
ANIMAL = "Goat"
dtest = cow.script.test
Now if I export this dungeon, start the game, and try calling both function references:
Code: Select all
cow.script.test()
Cow
goat.script.test()
Cow
We can see that both fields have cow.script as their local environment.
But if I save and reload the dungeon, then try the test again:
Code: Select all
cow.script.test()
Goat
goat.script.test()
Goat
Now both fields have goat.script as their local environment! If you're ever going to hold references to a function outside of the script that defines it, don't try to use the local environment. It will absolutely bite you in the ass.
On the other hand, this is really useful if you want to detect when the player reloads the game!