Problem with counters

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
SeyProdumen
Posts: 18
Joined: Fri Jul 26, 2013 7:00 pm
Location: Norway
Contact:

Problem with counters

Post by SeyProdumen »

Now I have a very odd problem. I'm working on a puzzle where in a set of 4 buttons each one has to be activated a given amount of times to open a door.

I have connected each button to a counter starting on 0, with the button increasing the counter by one. The counters are connected to a script entity, which they trigger on any event. There's a fifth button which only resets the counters in case the player made a mistake. Now this is my script:

Code: Select all

function door()
	if counter_1:getValue() == 1 and
	counter_2:getValue() == 2 and
	counter_3:getValue() == 1 and
	counter_4:getValue() == 3 then
	dungeon_door_portcullis_2:open()
	end	
end
The thing is, it only works when ending the sequence with one of the buttons which have to be pressed just once. I have a feeling that it's got to do with the counters being set to "any" - I did this because I understand counters only "activate" on 0, and by having the counters increase I don't need to worry about what happens when the player presses a button too often, as the door just won't open.

What's going on? :?
User avatar
DesperateGames
Posts: 90
Joined: Sun Oct 06, 2013 1:54 pm

Re: Problem with counters

Post by DesperateGames »

It took me some to think time as I have almost no experience with the counters, but I might know what the problem is:

You have your counters set to execute the script at "any" event. This means that the script will be triggered when the counter is activated, and when it is deactivated. The problem is that for the multiple button presses, the script won't be executed on the last press of the button, because the counter has already been activated with the first press. You can avoid this problem by removing the connectors between counters and the script, and instead use additional connectors from the BUTTONS to the script (using "toggle"-event). This should ensure that the script function gets called every time a button is pressed, and the door should open as soon as the correct combination has been entered.
SeyProdumen
Posts: 18
Joined: Fri Jul 26, 2013 7:00 pm
Location: Norway
Contact:

Re: Problem with counters

Post by SeyProdumen »

That seems to have done the trick! :D Thank you so much! Sometimes making a puzzle feels like a puzzle in itself, especially if you have little experience with scripting, haha. I was not aware of the exact way counters "activate" and "deactivate".
Post Reply