LOG 1 secret & sound

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

LOG 1 secret & sound

Post by RayB »

I have placed a tomb of health in a dungeon alcove behind a secret door. I set up the alcove to play the 'Secret' sound on 'deactivate'. You pick up the tomb, the 'secret' sound plays. It worked great in the dungeon editor but when I exported the file and tried it in the custom game it doesn't work. Can anyone tell me why this is so? Is there a work around or is this just a quirk I will have to put up with? I know I can use a hidden pressure plate, but I am curious as to why the alcove won't set off the sound.
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Re: LOG 1 secret & sound

Post by trancelistic »

So far I know. The basic, placing an alcove only triggers if something is put in it ( not taken out).

So short said. If you take something out of the alcove nothing will trigger. Only if an item is placed in.

Ofccrouse a script is possible to check to alcove but then again a hidden press plate would be easier.
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: LOG 1 secret & sound

Post by RayB »

But if what you say about only working when you put something in, why does it work just fine in the dungeon editor?
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: LOG 1 secret & sound

Post by Isaac »

Altars, and Alcoves trigger either when an item is first added to [an empty] one; or when the last item is removed.

The "Activate Always" optional setting for alcoves and altars, ensures that it will (instead) trigger anytime an item is inserted or removed.
*This can be problematic though; as the alcove would trigger the same for placing a rock on it, as it would for removing the tome of health.

What you might want to do is to connect the alcove to a script_entity, one with a function to check the alcove for the tome, and trigger the secret only when the tome is not found in the alcove. This would filter out cases where the player added items to the alcove, and/or never touched the tome.

An example script that checks a connected alcove or altar for a tome of health:

Code: Select all

    function itemChk(alcove)
       for item in alcove:containedItems() do
          if item.name == "tome_health" then
             return
          end
       end
       local temp = findEntity("health_tome_secret")
       if temp then
          temp:activate()
       end
    end
The script looks for a secret named "health_tome_secret".
(Note: You do not connect the alcove to the secret.)
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: LOG 1 secret & sound

Post by RayB »

I can see the problem you are talking about. But the chances are remote that someone, after finding the tome, would stick more stuff in the alcove rather than just pick up the tome so I kind of overlooked it, especially after I discovered that each secret sounds only once. However, it is possible, and because I like to make things as full-proof as I can, I used your script. IT WORKS GREAT!

Thank you very much.

There is one thing I do not understand though. In the first line you use ‘alcove’ as a parameter. Can you explain this? It seems that somehow you are passing the dungeon alcove itself to the script as a parameter (or argument) to the variable ‘alcove’ If this is so, why were you able to use ‘alcove’ and not ‘dungeon_alcove’ as it is called in the editor? I thought at first that maybe ‘alcove’ was the distinctive ID but if that were so it wouldn’t have to be passed at all to use it in the next line (alcove:containedItems()) .

I have been doing similar things but I did not know the entity could be passed to the function so I have been having the entity call a function and then letting that function call the working one. For example if the alcove were named ‘tomeAlc’ I would do something like…

function tomeAlcChk() --called when alcove ‘tomeAlc’ deactivates
itemChk(tomeAlc)
end

function itemChk(alcove) --item ‘tomeAlc’ gets passed to ‘alcove’
for item in alcove:containedItems() do
if item.name == "tome_health" then
return
end
end
local temp = findEntity("health_tome_secret")
if temp then
temp:activate()
end
end

I like what you did. I just don’t understand how you did it. How did you pass the alcove entity to the function using the single word 'alcove'. Is the word 'alcove' some sort of key word or do all entities pass themselves when calling a function and all you have to do (if desired) is supply a variable? If 'alcove' is a 'key' word is there is list of these somewhere?

Thanks again, RayB
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: LOG 1 secret & sound

Post by Isaac »

When you call a function using a colon, that includes the caller itself as the first argument.
When you call a function using a period, it does not.

You can connect this script to a button, plate, lever, and a torch. It will print what kind of object triggered it; and it first calls itself three different ways, and prints that.

Code: Select all

   
 --The first argument, (depending on how it was called), can be the object that called the function.
 function whoIs(caller, superfluousData)
       if not superfluousData then superfluousData = "no extra arguments."
       end
       if not caller then
          caller = {name = "script_entity, without passing itself as the first argument"}
       end
       print("Called by a "..caller.name..", and with "..superfluousData)
    end

    self:whoIs("a string as the second argument.")

    self.whoIs()

    self.whoIs(nil,"a string as the second argument.")
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: LOG 1 secret & sound

Post by RayB »

Thanks very much. That clears up a lot. I was also unaware of the difference between the ':' and the '.' in the calls.
User avatar
Eleven Warrior
Posts: 736
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: LOG 1 secret & sound

Post by Eleven Warrior »

Bloody awesome Issac man your the best :)
CharleCew
Posts: 2
Joined: Wed Jun 03, 2015 4:11 pm

LOG 1 secret sound

Post by CharleCew »

what is the difference between using 44khz sound files and 22Khz files?
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: LOG 1 secret & sound

Post by minmay »

44.1 KHz is "CD quality" and the most common sample rate these days. It's the standard in Grimrock.
22 KHz is half the resolution, generally sounds like crap, and there aren't many places where you'd want to use it in a mod. Maybe if the sound lacks high end in the first place, or is masked by a lot of other sounds.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply