Page 1 of 2
Problem with 'Surface Contains' script Please Help
Posted: Sun Jul 03, 2016 7:56 pm
by Mortis_of_Midian
Please Help
As part of a puzzle I'm working on I have an Altar onto which the player places a spiked_club and the club is teleported away to an inaccessible room and an Ogre is spawned.
This is supposed to give the illusion that the Altar performs some kind of necromatic magic and resurrects the Ogre that the club belonged to.
Code: Select all
function surfaceContains(surface, item)
for v,i in surface:contents() do
if i.go.name == item then return true
end
end
end
function ogreAltar()
if surfaceContains(catacomb_altar_candle_01_1.surface, "spiked_club") then
hudPrint("Club Placed")
teleporter_24.controller:activate()
timer_2.timer:start()
else
hudPrint("That does nothing")
end
end
I've used code from an alcove puzzle to perform this function - and it does work - but only the once.
The first time I place spiked_club it works as expected - but any time after that it doesn't matter what I place on the Altar it always activates. I don't understand why this is, do I need to 'reset' the code or the surface component some how? Or have I just stumbled upon a limitation of LoG2?
Re: Problem with 'Surface Contains' script Please Help
Posted: Sun Jul 03, 2016 8:09 pm
by Zo Kath Ra
How do you teleport the club away?
Re: Problem with 'Surface Contains' script Please Help
Posted: Sun Jul 03, 2016 8:14 pm
by Mortis_of_Midian
Zo Kath Ra wrote:How do you teleport the club away?
A teleporter (teleporter_24) is placed over the Altar - it's starts deactivated and is activated by the script ( "teleporter_24.controller:activate()" )
when timer_2 finishes it's cycle it then deactivates the teleporter ready for next time
Re: Problem with 'Surface Contains' script Please Help
Posted: Sun Jul 03, 2016 9:21 pm
by Zo Kath Ra
The problem is this:
If there's an item on the altar, and you teleport the item away, then the item is still on the altar's surface (as far as the game is concerned).
The only way to remove an item from a surface (other than picking up the item) is to destroy the surface, which also destroys the item.
You can use this function instead:
Code: Select all
function ogreAltar(self, item)
if (item.go.name == "spiked_club") then
hudPrint("Club Placed")
teleporter_24.controller:activate()
timer_2.timer:start()
else
hudPrint("That does nothing")
end
end
Connect it to the altar's onInsertItem connector, and it should work.
Re: Problem with 'Surface Contains' script Please Help
Posted: Sun Jul 03, 2016 9:42 pm
by minmay
There is no known way to remove an item from a surface using the scripting interface, except for outright destroying the ItemComponent. Even destroying the surface taints the item and will result in a crash on saving or attempting to pick up the item.
It would be very nice if someone found a way to remove an ItemComponent from a surface without destroying it, but currently I know that the following do NOT work:
- naively changing the parent object's position (teleporters, setPosition(), etc)
- adding the item to an inventory (player, monster, surface, socket, container, doesn't matter, none of them actually remove the item from the surface, even adding it to a monster's inventory and making the monster drop it)
Re: Problem with 'Surface Contains' script Please Help
Posted: Sun Jul 03, 2016 9:54 pm
by Mortis_of_Midian
ok I'm not too bothered about where the club goes (I only used a telepoter as it seemed like most simple way at the time) so it might as well be destroyed - how would I go about that?
if the surface is destroyed to clear it, can I put the surface back? will it work a 2nd time?
I've seen 'shop' type setups which make one item disappear and replace it with another, but I'm not sure how they work
thanks for the replies

Re: Problem with 'Surface Contains' script Please Help
Posted: Sun Jul 03, 2016 10:15 pm
by minmay
Code: Select all
function ogreAltar(self, item)
if (item.go.name == "spiked_club") then
hudPrint("Club Placed")
item.go:destroyDelayed()
else
hudPrint("That does nothing")
end
end
Re: Problem with 'Surface Contains' script Please Help
Posted: Sun Jul 03, 2016 10:21 pm
by Mortis_of_Midian
Here's a thought - is there a way to make teleporter do the 'detecting' rather than the altar?
I will also try the code posted above tomorrow, thanks guys
Re: Problem with 'Surface Contains' script Please Help
Posted: Sun Jul 03, 2016 10:23 pm
by Isaac
Mortis_of_Midian wrote:ok I'm not too bothered about where the club goes ...
If it's just a visual prop (that they never touch before it's gone), then it doesn't actually need to be the functional item. You could make it part of the altar, and disable it when it needs to vanish.
Re: Problem with 'Surface Contains' script Please Help
Posted: Sun Jul 03, 2016 10:57 pm
by Mortis_of_Midian
Isaac wrote:
If it's just a visual prop (that they never touch before it's gone), then it doesn't actually need to be the functional item. You could make it part of the altar, and disable it when it needs to vanish.
Ah no, the characters need to be able to handle the club. I've got a puzzle where you need to trap 4 ogres in 4 cages. Of course if the player kills an ogre then the puzzle can't be completed so I wanted to be able to replace dead ogres with fresh ones and with something a bit more immersive than a button that spawns them on demand or a new ogre spawning upon the death of an old one. Also exchanging a club for an ogre via the altar naturally limits the number of ogres in game and allows for the additional element of searching for clubs hidden around the cages.