Page 1 of 1

Spike Trap Script Help Needed

Posted: Fri Nov 07, 2014 5:16 am
by Echoplex
First time posting here, trying(albeit failing) to wrap my head around Lua. I'm trying to code a simple spike trap that would work off of a timer. The trap would activate spike traps in a pattern(Im thinking determined by a timer) however I can't get the darn traps to spring using a Script. Here's the test run I have below but obviously I fail at Lau language and cant get it to fire off. I have a timer connected to the script Lau. Im thinking im not defining what the floor_spike_trap is I.e. a trap but im not sure what its called or maybe im totally off base here. Anyway any help is much appreciated.

function Spikestrap()

if timecount == 1 then
floor_spike_trap_7:activate()

elseif timecount == 2 then
floor_spike_trap_8:activate()
end
timecount = 1
return
end

Re: Spike Trap Script Help Needed

Posted: Fri Nov 07, 2014 10:48 am
by Prozail
floor_spike_trap_7.controller:activate()

is what youre looking for. Also i made a kind of basic spike-trap thingy here

Re: Spike Trap Script Help Needed

Posted: Fri Nov 07, 2014 11:01 am
by Blichew
When do you deactivate the traps ? With your example they will both be activated after 2 secs (timer ticks). Also: you're setting timecount to 1 every time the function runs (it's outside the elsif clause). If you want it to cycle you have to do something like that:

Code: Select all

function Spikestrap()
	if timecount == 1 then
		floor_spike_trap_7.controller:activate()
		floor_spike_trap_8.controller:deactivate()
	elseif timecount == 2 then
		floor_spike_trap_8.controller:activate()
		floor_spike_trap_7.controller:deactivate()
		timecount = 1
	end
end
also: @Prozail - thinking about next video tutorial :) ?

Re: Spike Trap Script Help Needed

Posted: Fri Nov 07, 2014 11:04 am
by Prozail
You don't need to deactivate them asfaik. Activate just does a one-shot.

Re: Spike Trap Script Help Needed

Posted: Fri Nov 07, 2014 11:05 am
by Blichew
Oh, then I've just added two useless lines to this code :) still timecount has to be under elsif to alter between 1 and 2

Re: Spike Trap Script Help Needed

Posted: Fri Nov 07, 2014 4:07 pm
by Echoplex
Doh controller! Thank you, when I get some time ill check it out. Thank you for the responses everyone.