Timer Script Help Needed

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
HypnoToad
Posts: 73
Joined: Thu Sep 22, 2016 1:19 am
Location: Melbourne, Australia

Timer Script Help Needed

Post by HypnoToad »

This is my first post in this wonderful forum, I am making a custom dungeon and want to have a series of pits that open and close at intervals, I have done that part and it works fine after hours of head scratching and reading up on this forum. I have the lever connected to the timer which is connected to the script.

However when you mistime it and fall into the pit I don't know how to reset everything so the person can start again at the beginning, I have a lever to start off the sequence but no way to stop it and reset it.

Here is the script I have devised:

time = 0
function RunTimer()
if time == 1 then
dm_floor_pit_12:close()
elseif time == 2 then
dm_floor_pit_13:close()
elseif time == 3 then
dm_floor_pit_12:open()
dm_floor_pit_14:close()

--------------- It's long so I cut out the middle part on here as it just repeats until the next line -------------

elseif time == 18 then
mytimer_1:deactivate()

end
time = time + 1
end

Any help would be greatly appreciated.
User avatar
THOM
Posts: 1266
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Timer Script Help Needed

Post by THOM »

mh - I think if you add after

Code: Select all

mytimer_1:deactivate()
a line like

Code: Select all

time = 0
it should do the trick. Then if your sequence has run it also will be reseted...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
HypnoToad
Posts: 73
Joined: Thu Sep 22, 2016 1:19 am
Location: Melbourne, Australia

Re: Timer Script Help Needed

Post by HypnoToad »

THOM wrote:mh - I think if you add after

Code: Select all

mytimer_1:deactivate()
a line like

Code: Select all

time = 0
it should do the trick. Then if your sequence has run it also will be reseted...
Thank you so much it works, and it makes sense that it needs to be reset to 0.

I am not one to just ask for help unless it's absolutely necessary but it had me stumped.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Timer Script Help Needed

Post by Isaac »

HypnoToad wrote: --------------- It's long so I cut out the middle part on here as it just repeats until the next line -------------
If it's long, then there is [possibly] a shorter way to do it; certainly a way that is easier to change and/or reuse later.

A table can be used to record the unique identifier for each of the pits, and in so doing allows both for arbitrary number of pits, and for the pattern of opening & closing to be written into the table itself; and be easily changed.

Example:

Code: Select all

time = 0
name = "temple_pit_"  --prefix of the pit object name
dirSwap = false
direction = false -- forward
pits = {1,2,7,8,9,10,15,20,19,14,13,12,17,18,19,24}  --number suffix of the pit object name (id)

function altRunTimer()
	time = time + 1 
	
	if dirSwap then             -- when true, reverses the pits array to play out the pattern backwards; for the return trip.
		pits = _reverse(pits)
		dirSwap = not dirSwap
	end	
			
	if time <= #pits then	    				
		findEntity(name..pits[time]):toggle()			-- toggles the current pit
		if time -2 > 0 then
			findEntity(name..pits[time-2]):toggle() 	-- potentially toggles the previous pit
		end		
	 else time = 0								-- else it's reached the end of the pattern; sets the next pass to reverse.
		direction = not direction
		dirSwap = not dirSwap						
		for x = 1, #pits do					-- opens all pits before restarting
			findEntity(name..pits[x]):open()
		end
	end	
end








function reset()  -- optional reset feature; starts the pattern from the initial beginning. Restores [Re-Reverses] the pits array if it is currently backwards
	time = 0
	if direction then
		pits = _reverse(pits)
		direction = false
	end

	for x = 1, #pits do					-- opens all pits before restarting
		findEntity(name..pits[x]):open()
	end	
end






function _reverse(table)   		-- function to reverse the array when called. Takes table as argument instead of using pits. It should be copy/paste ready for other scripts 
	local input = type(table)
	if input == "table" and type(table[1]) == "number" then
		local revTable = {}
		for i in ipairs(table) do
		    revTable[i] = table[(#table+1)-i]
		end
		return revTable
	end
	print("ERROR: Expected table of numbers")		
end
Project file: https://www.dropbox.com/s/uw43n4kp4umkw ... s.zip?dl=0
User avatar
HypnoToad
Posts: 73
Joined: Thu Sep 22, 2016 1:19 am
Location: Melbourne, Australia

Re: Timer Script Help Needed

Post by HypnoToad »

Isaac,

That's amazing, I just have mine in a straight line in a corridor but the trick is the timing varies, so you have to be on your game or you end up either walking into the next one or falling into the one your on.

I will have to try yours out. Thanks for the files.

HypnoToad
User avatar
HypnoToad
Posts: 73
Joined: Thu Sep 22, 2016 1:19 am
Location: Melbourne, Australia

Re: Timer Script Help Needed

Post by HypnoToad »

I will say one thing about making a custom dungeon, you don't realize until you play through it for real how many mistakes you need to correct, I have at least half a dozen updates so far.

It's done but still testing it out and fine tuning things, hope to put it on here soon.
Return of the Dark Lord - V3.5 Download:
https://www.nexusmods.com/grimrock/mods ... escription
User avatar
THOM
Posts: 1266
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Timer Script Help Needed

Post by THOM »

Oh yes. Same here... :?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
HypnoToad
Posts: 73
Joined: Thu Sep 22, 2016 1:19 am
Location: Melbourne, Australia

Re: Timer Script Help Needed

Post by HypnoToad »

Just one more question does someone have a script for a combination lock?

That is you have three buttons and you have to for example press button 1 twice, button 2 four times and button 3 three times, I have seen them where you press different buttons in a sequence but not one like this, I have been working on one but can't get it to work, I can get the buttons to reset after so many presses but don't know how to get it to register to open a door or such.


function buttonOne()

if counter_1:getValue() == 4
then counter_1: ???????? <----- I think I need something here to connect to another function so if all are correct the door opens or I may be way off

elseif counter_1:getValue() == 6
then counter_1:reset(0)
hudPrint("The button was reset.")
end
end
Return of the Dark Lord - V3.5 Download:
https://www.nexusmods.com/grimrock/mods ... escription
User avatar
THOM
Posts: 1266
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Timer Script Help Needed

Post by THOM »

Have a look at this post
viewtopic.php?f=14&t=3026&hilit=buttons&start=10#p37586

and at this one
viewtopic.php?f=14&t=4461#p46505

In both are solutions for a button/lever sequence script shown.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
HypnoToad
Posts: 73
Joined: Thu Sep 22, 2016 1:19 am
Location: Melbourne, Australia

Re: Timer Script Help Needed

Post by HypnoToad »

Thanks so much.

I eventually tried this and it worked:

Code: Select all

function comboLock()

    if counter_1:getValue() == 2
    and counter_2:getValue() == 1
    and counter_3:getValue() == 3
    then door_1:open() 

end
end
And then put new functions to reset the counters which is a bit messy but I will read up on what you posted, I'm sure there is an easier way in there.
Return of the Dark Lord - V3.5 Download:
https://www.nexusmods.com/grimrock/mods ... escription
Post Reply