Hooks get a different environment than init scripts. It's similar to the environment that ScriptComponents get.
There are three options:
1. Make it an upvalue by defining it as a local function. However, if you do this, you have to make sure to only use it in functions that don't get serialized.
2. Move it to a ScriptComponent in the dungeon. This can be annoying to maintain.
3. Put it in a table that is available in both environments, such as Config:
Code: Select all
print("skript loaded")
Config.qpttest = function()
print "test called"
end
Config.qpttest()
defineObject{
name = "breadling",
baseObject = "bread",
components = {
{
class = "Item",
uiName = "breadling",
gfxIndex = 1,
onEquipItem = function(self, champion, slot)
hudPrint(champion:getName().."uses breadling.")
if (Config.qpttest ~= nil) then
Config.qpttest()
else
print("qpttest not defined")
end
end,
},
},
}
This last approach is the most hacky of the three, but it's also the closest one to your desired functionality (sharing an environment between init scripts and hooks). Note that any changes made to Config (and the other "global" tables) will not be serialized, and will persist until the game is closed. This is fine for a case like this one, but it means you shouldn't try to store mutable data in it for instance.