brzrkr wrote:2. Why does it say that "gameobject" or "go" doesn't exist?
Because it doesn't. All of the gameobject methods are accessible as object:method()
Code: Select all
Try this in the hook:
function smotherLantern(monsta)
print(monsta.go.id, unpack{monsta.go:getPosition()})
for monster in monsta.go.map:entitiesAt(monsta.go.x, monsta.go.y) do
if monster.monster and not monster.go then -- notice that the condition FAILS if there is a value for monster.go
print(monster.id, unpack{monster:getPosition()}) -- notice that this is not monster.go.id
end
end
end
The .go field is used when accessing the script object; which is generally the first argument passed to your function. In function(self), self.go.id gives the id of the script. [monsta is the script, and needs to be monsta.go.id]
And the wall lantern has that same exact ID.
No two objects [existing concurrently] on the map should have the exact same id. That will crash it.
[Except in the dangerous case where of one of them is in a container on the map].
How am I supposed to destroy the lantern or disable one of its components when the monster dies, if this is not the correct way?
If its id is 'Lantern' then the way is: Lantern:destroy()
3. About the commented part, since the dying monster's ID is villageMummy, I was wondering if I could take his id, append "Lantern" to it in a string (thus creating the lantern's ID), and then use the string variable as if it were the lantern ID itself, to destroy the lantern directly. If not, how can I turn that string into the actual lantern entity?
.
You
could set it up this way by manually naming the objects. When you have a concatenated string and need to use it as an ID, use the function findEntity() in place of the id, and pass to it the string.
Examples:
findEntity("my_object_1"):destroy()
local obj = "my_object_"..x --where x == 1
findEntity(obj):destroy()
Know that findEntity will return nil, if it cannot find the object ~that can crash your script if unexpected. So if there is a chance of it returning nil, you can first check that it's not nil.
Example:
if findEntity("my_object_1") then findEntity("my_object_1"):destroy() end