Continual projectile spawner

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
ConfusedBear
Posts: 4
Joined: Tue Oct 16, 2012 9:52 pm

Continual projectile spawner

Post by ConfusedBear »

Hi all,

I'm fairly new to LUA scripting, so please excuse the potentially silly questions that will no doubt follow ;)

I'm trying to make a spawner shoot poison_bolts continually until a lever is in the activated state. So I created a lever and a 'for' loop script that in theory checks for the state of a lever and if it's deactivated, then do something. When I try and do this code...

Code: Select all

function poison()
	for i in lever_lv2PoisonLever:getLeverState() do
		if i.LeverState == "deactivated" then
			spawner_lv2PoisonSpitter:activate()
		else
			spawner_lv2PoisonSpitter:destroy()			
		end
	end
end
...I get the error 'attempt to call a string value' on line 2. My attempt to work around this was to use another script that sets the counter and then maybe modify the above script to use this numerical state instead. Using this code:

Code: Select all

function workplease()
	if lever_lv2PoisonLever:getLeverState() == "deactivated" then
		counter_2.setValue(0)
	end
end
Then flicking the lever back to deactivated gives me the more vague error 'bad self' on line 3.

I might be using a completely arcane approach for which there's a very simple answer (I couldn't see a 'continual' flag on the spawner...). Any suggestions for how I can fix this would be most welcome!

Thank you.
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Continual projectile spawner

Post by msyblade »

If i follow what you're trying to do correctly. Simply make a hidden pad the player triggers previously, to start a continual timer (say like 3 sec's?) hooked to a poison_bolt spawner, then the lever deactivates the timer instead? and u could make de-activate start it back up if u like.
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
ConfusedBear
Posts: 4
Joined: Tue Oct 16, 2012 9:52 pm

Re: Continual projectile spawner

Post by ConfusedBear »

msyblade wrote:If i follow what you're trying to do correctly. Simply make a hidden pad the player triggers previously, to start a continual timer (say like 3 sec's?) hooked to a poison_bolt spawner, then the lever deactivates the timer instead? and u could make de-activate start it back up if u like.
That's exactly what I was looking to do! The simplest solutions are always the best. Many thanks for the prompt answer!
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Continual projectile spawner

Post by msyblade »

Good, I'm glad I could help. Script entities in the editor are really only good for making text, Starting sounds, or checking for a very specific set of circumstances on an object before reacting. Otherwise, timer, counters, and activate once features can do most everything you want.
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Continual projectile spawner

Post by Komag »

Using a timer to repeatedly trigger something is one of the most powerful approaches to use. You can even have it do something different every time, because you can have the last thing it did also change a number or something, and then the next time it checks the number and sees that it's different so it does different instructions based on your scripting code.
Finished Dungeons - complete mods to play
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Continual projectile spawner

Post by msyblade »

And it should be noted that if you only want the timer to activate once, you connect it to itself to deactivate, or else all timers are continuous (took me a bit to catch onto that.)
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
Post Reply