Question about sound loops.

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Question about sound loops.

Post by trancelistic »

Hey all,
I was wondering. If i made a timepuzzle,
Let say hit a switch and you got 8 seconds to enter a teleporter.
I want to play a tensed little timer sound for its duration. ( I've made that wave and it works)
But hitting the switch multible times causes the *.wav file to played over and over. How to prevent this? ( Like if i pressed the switch 8 times within the 8 sec timer, then that *.wav is played 8 x at the same time, I do not want this"

Any advise on this? That would be great.

Ps: Vink: "Activate only onces" doesn't work because if they fail on the first attempt to find the teleporter then they are stuck in the game. They should be able to press the switch again and then the 8 sec *.wave also plays again.
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Question about sound loops.

Post by THOM »

Depending on your script it's not only the sample, that is started over and over again but also the timeslot itself. So if a player hits the button again, he can enlonging the time as long has he/she wants...

I think you have to add a variable - a counter or in your script a local a = 0.

On hitting the button there must be a query of the value of the counter/variable, after starting the time the counter/variable must be incremented and as long as it is = 1 the button doesn't work anymore. At the end of the sample/time, the value must be set back to zero.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Question about sound loops.

Post by Isaac »

Place and add a connection to the timerSound function. The player can press the as many times as they wish, but the script ignores it until the time is up.

Code: Select all

duration = 8 --seconds
ignore = false

function timerSound()
	if not ignore then
		ignore = true
		for x = 1,duration do
			delayedCall(self.go.id,x,"sound", "lock_incorrect") --set sound effect
		end
		delayedCall(self.go.id,duration,"resetIgnore")
	end
end

function sound(sample)
	playSound(sample)
end

function resetIgnore()
	ignore = false
end
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Re: Question about sound loops.

Post by trancelistic »

Thanks to both of you. Uhm to Isaac:

delayedCall(self.go.id,x,"sound", "lock_incorrect") gives an error : "attempt to index field 'go' a nil value x"

No idea how to solve this.
yes I'm a noob haha.:( sorry about that.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Question about sound loops.

Post by minmay »

The script Isaac posted is only for Grimrock 2.
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.
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Re: Question about sound loops.

Post by trancelistic »

minmay wrote:The script Isaac posted is only for Grimrock 2.
Haha that explains it:)

Ahhhh I almost solved it then the editor crashed:S:S
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Re: Question about sound loops.

Post by trancelistic »

Isaac I need 1 more time your help. I think I solved it with some timers combined and scripts.

The only thing that is happening now is: I destroy'd a lever. The timer later activates a script that will repawn the lever and that is connected to the same timers/scripts as the REAL lever was before it was destroyed.
However the script says now that the lever isn't found while I clearly pulled the lever in game. ( so it did respawned with the correct IDname)

Any idea's what I did wrong?

So basicly lever pulled == activated. It activates a timer, after 0.01 seconds it will run a script telling it to destroy that lever
Another timer after 12 secs runs a scritp to respawn that lever again on the same location and its linked again to the timers. However then I get the message that the lever isn't found ( But i see it being spawned in game)

O_O


I hope I made sense haaha.
Post Reply