You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, I wanted a function to execute on an object when it spawns, but being a noob (I've managed to stay away from activities that required me to code for several decades), I did some testing first.
on Global:
function onObjectSpawn(object)
print('onObjectSpawn got triggered by '..object.getGUID())
object.call("onSpawn")
end
on the Object:
function onSpawn() --called by Global onObjectSpawn()
print('onSpawn got called on'..self.getGUID())
end
However, to my surprise, every copy/paste of the object printed "'onSpawn got called on.." twice, so eh?!?
I renamed "onSpawn" to "onSpawn2", then it got printed just once. Old name, but no Global script also leads it to printing it once.
New name, no Global script: zero. I conclude there exists a function "onSpawn()" that gets called when the script-owner Object spawns. Useful, but I cannot find any documentation on it in the API or anywhere else. I was even looking for such a function before deciding to use onObjectSpawn(). So: 🤬!
This really should be documented. No idea how to do this or who is in charge of doing it, just saying it's something worth doing. I found out the problem relatively quickly because the above was literally the only scripting going on. In a larger script, it could have taken ages to figure out what was going on. Especially for a noob like me.
The text was updated successfully, but these errors were encountered:
So, I wanted a function to execute on an object when it spawns, but being a noob (I've managed to stay away from activities that required me to code for several decades), I did some testing first.
on Global:
function onObjectSpawn(object)
print('onObjectSpawn got triggered by '..object.getGUID())
object.call("onSpawn")
end
on the Object:
function onSpawn() --called by Global onObjectSpawn()
print('onSpawn got called on'..self.getGUID())
end
However, to my surprise, every copy/paste of the object printed "'onSpawn got called on.." twice, so eh?!?
I renamed "onSpawn" to "onSpawn2", then it got printed just once. Old name, but no Global script also leads it to printing it once.
New name, no Global script: zero. I conclude there exists a function "onSpawn()" that gets called when the script-owner Object spawns. Useful, but I cannot find any documentation on it in the API or anywhere else. I was even looking for such a function before deciding to use onObjectSpawn(). So: 🤬!
This really should be documented. No idea how to do this or who is in charge of doing it, just saying it's something worth doing. I found out the problem relatively quickly because the above was literally the only scripting going on. In a larger script, it could have taken ages to figure out what was going on. Especially for a noob like me.
The text was updated successfully, but these errors were encountered: