Page 1 of 1

Continual projectile spawner

Posted: Tue Oct 16, 2012 10:16 pm
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.

Re: Continual projectile spawner

Posted: Tue Oct 16, 2012 10:37 pm
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.

Re: Continual projectile spawner

Posted: Tue Oct 16, 2012 10:43 pm
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!

Re: Continual projectile spawner

Posted: Tue Oct 16, 2012 10:47 pm
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.

Re: Continual projectile spawner

Posted: Wed Oct 17, 2012 12:23 pm
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.

Re: Continual projectile spawner

Posted: Wed Oct 17, 2012 3:52 pm
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.)