Scripting Problem: Sequence Lock (solved)

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Montis
Posts: 340
Joined: Sun Apr 15, 2012 1:25 am
Location: Grimrock II 2nd playthrough (hard/oldschool)

Re: Scripting Problem: Sequence Lock

Post by Montis » Tue Sep 18, 2012 6:51 pm

Green Cube wrote:
With my new script you can actually make any sequence. E.g. pull lever 1,4,4,2,3,1,3,2,2,3,1 ...
Don't worry, I love you all equally. :P

There is a problem with the script however. If you pull more than how many levers were determined by the counter the game crashes with a nil value error. I "fixed" it like this:
SpoilerShow

Code: Select all

function sequenceRiddle()

   local triggerEntity = "lever"
   local namingPattern = "lever_"
   local sequenceOfThings = {"1","2","3"}
   local sequenceCounterID = "myCustomSequenceCounter"

   local curSeq = #sequenceOfThings+1-myCustomSequenceCounter:getValue()

   for i in entitiesAt(party.level, party.x, party.y) do

      if i.name == triggerEntity then
		 if( myCustomSequenceCounter:getValue() == 0 ) then
		
			 	myCustomSequenceCounter:reset()
			 	sequence_door:close()
			
         elseif i.id == namingPattern..sequenceOfThings[curSeq] then
            findEntity(sequenceCounterID):decrement()

         end

      end

   end

end
Maybe it already worked though and I just screwed up.
you can also just connect the counter with itself (in addition to the door) and tell it to reset when activated (activate = reaches zero).
When destiny calls, the chosen have no choice.

My completed dungeon (LoG1): Hypercube

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Scripting Problem: Sequence Lock (solved)

Post by akroma222 » Fri Oct 05, 2012 10:08 am

Hey Peoplez,

Am I able to use this coding if my 3 activationh entities are different kinds of buttons?? (ie, a small secret button, a large secret button and a wall button)?? It has been mentioned that this coding is doable for levers or buttons (but not a mixture of both I assume?)

I have followed Montis' coding for this and followed the instructions word for word as above (THANK YOU SIR! - except for - sequenceSecretDoor1 and triggerEntity = "button") and I can not get it to work :oops: .... obviously when I connect the activation entities, given they are buttons, I can only choose -event:toggle- not -event:activate- as instructed....

Hmmmmm

Right! So I changed all the different kinds of buttons to just levers (sequenceLever1-3 and obviously triggerEntity to "lever") and it works fine. So I guess the issue is the different kinds of buttons used in the same puzzle. Will leave it with levers for now 8-)

Further I guess it should be mentioned that these buttons/levers were sprayed around a room that supported 2 rotating teleporter maze puzzles...evidently not interferring with the sequencing.

Thanks again all of you!

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Scripting Problem: Sequence Lock (solved)

Post by akroma222 » Sat Oct 06, 2012 12:47 pm

OK, so I have copied and pasted the coding from above and instead have used pressure plates (triggerEntity = "plate".. also tried "pressure_plate")... but ze door will not open!?

I have tried running over the plates and also leaving items on them (in order) but to no avail....
How would one need to change this coding for pressure plates?

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Scripting Problem: Sequence Lock (solved)

Post by akroma222 » Tue Oct 23, 2012 8:51 am

In an attempt to ressurect my plate sequence riddle, I tried using Montis' sequence riddle code (the one posted up in the super thread) in conjunction with Komag's suggestion of connecting plates to scripts which then toggle a lever (then connecting the lever to the aforementioned riddle script)....
SpoilerShow

Code: Select all

-- plate lever toggle
function platetoggle()
     mylever:toggle()
end
The idea behind this is that you can hide the levers elsewhere so it seems the plates are doing all the work (with no intermediate lever/scripting)
Unfortunately though, the sequence riddle script requires the party to be at the space of the lever for it to trigger the sequence solution.... (the levers are still toggled by the plates), hense, defeating the purpose of hiding the levers, which = doesn't work.

Has anyone else had any success with creating plate sequence puzzles??

User avatar
Komag
Posts: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Scripting Problem: Sequence Lock (solved)

Post by Komag » Tue Oct 23, 2012 10:39 am

Can you explain a bit more detail about what you want to do exactly? If I have a better idea then I'm sure we can help with a good solution.

The idea to trigger levers was a very old one which I probably wouldn't do again now that I know more about how things work and about scripting.
Finished Dungeons - complete mods to play

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Scripting Problem: Sequence Lock (solved)

Post by akroma222 » Tue Oct 23, 2012 11:04 am

Ahh for sure Komag!
I have a room, with six pressure plates and two secret doors.
I am trying to create a simple sequence puzzle with the pressure plates (correct sequence of 3 to open 1 door, another sequence of 3 to open the other).

As ^^mentioned, I tried using the plates to trigger the lever toggle script (1 script for each) you have posted on a diff thread. The levers were then connected to the sequence riddle script that has been refined in this thread by Montis/Green Cube etc. Except, the seqeunce riddle requires the party to standing on the space containing the lever (I am pretty sure after testing diff lever positions) - as such - using the plate script to toggle hidden levers does not work. The whole rig up worked fine when the levers were on the spaces with their corresponding pressure plates though... which defeats the purpose lol :(

In essence, I would like to use plates for a sequence riddle :)

User avatar
Komag
Posts: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Scripting Problem: Sequence Lock (solved)

Post by Komag » Tue Oct 23, 2012 11:13 am

Are they entirely independent of each other? I mean, is it like you have plates A B C D E F, and to open door 1 you need to step on A, F, C, and to open door 2 you need to step on E, B, D, or something like that?

If so, it's easy to just set up each puzzle separately.

I have developed a decent sequence script, but it only applies to a sequence where each plate you have to step on in order is a different plate, with no repeats such as A, F, A.

If you have some overlap between the two puzzles, such as A, F, C for door 1 and E, F, D for door 2, that could make things a little more tricky, but not much. If you have repeats, like A, F, A, then my setup would have to be different, but not too much.
Finished Dungeons - complete mods to play

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Scripting Problem: Sequence Lock (solved)

Post by akroma222 » Tue Oct 23, 2012 12:01 pm

Ahh very cool Komag!
I hadn't even started to set up the 2nd plate sequence yet, I was still stumped on making the 1st work lol - so unsure to answer the question.
Using the same plate in both sequences opens up more permutations (which is better for puzzlyness), but it would definitely be handy to know how to manage the coding without...
I was not planning on using the same plate in a single sequence, however, which makes things simpler....

User avatar
Grimwold
Posts: 508
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Scripting Problem: Sequence Lock (solved)

Post by Grimwold » Tue Oct 23, 2012 12:28 pm

It might be worth noting here that a connector to a function in a script entity passes the triggering entity as a variable so you can set up a function that checks which plate called the function.

e.g.

Code: Select all

function checkPlate(self)
  if self.id == "plate_A" then
    -- do something here.
  else
    -- reset the puzzle here.
  end
end
so you could build a function up with multiple checks to see which plates have been previously pressed. You would need a way to store which plates have been pressed... either with variables defined outside the function, or by using counters tied to each step in the sequence.

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Scripting Problem: Sequence Lock (solved)

Post by akroma222 » Tue Oct 23, 2012 2:40 pm

Very interesting, thanks again Grimwold haha! ;)
I will have a muck around with this and repost when I have something decent...

Post Reply