Hello. I have probably stupid problem in my script. I created 3 buttons(1,2,3) and 3 spawners(1,2,3) my purpose was to open a gate after proper combination(2,3,1) and punish player(with poison cloud in the face) when he perpetrate a mistake.
function buttonPress(sender)
if sender.id == "wall_button_1" and counter_1:getValue() == 3 then
counter_1:setValue(3)
spawner_1:activate()
elseif sender.id == "wall_button_1" and counter_1:getValue() == 2 then
counter_1:setValue(3)
spawner_1:activate()
elseif sender.id == "wall_button_1" and counter_1:getValue() == 1 then
counter_1:setValue(0)
elseif sender.id == "wall_button_2" and counter_1:getValue() == 3 then
counter_1:setValue(2)
elseif sender.id == "wall_button_2" and counter_1:getValue() == 2 then
counter_1:setValue(3)
spawner_2:activate()
elseif sender.id == "wall_button_2" and counter_1:getValue() == 1 then
counter_1:setValue(3)
spawner_2:activate()
elseif sender.id == "wall_button_3" and counter_1:getValue() == 3 then
counter_1:setValue(3)
spawner_3:activate()
elseif sender.id == "wall_button_3" and counter_1:getValue() == 2 then
counter_1:setValue(1)
elseif sender.id == "wall_button_3" and counter_1:getValue() == 1 then
counter_1:setValue(3)
spawner_3:activate()
end
end
counter_1 has initial value = 3
every click on the button should run the script
Can sb halp ?
Last edited by Kaold on Sun Jul 06, 2014 1:42 pm, edited 1 time in total.
Kaold wrote:Hello. I have probably stupid problem in my script. I created 3 buttons(1,2,3) and 3 spawners(1,2,3) my purpose was to open a gate after proper combination(2,3,1) and punish player(with poison cloud in the face) when he perpetrate a mistake.
function buttonPress(sender)
if sender.id == "wall_button_1" and counter_1:getValue() == 3 then
counter_1:setValue(3)
spawner_1:activate()
elseif sender.id == "wall_button_1" and counter_1:getValue() == 2 then
counter_1:setValue(3)
spawner_1:activate()
elseif sender.id == "wall_button_1" and counter_1:getValue() == 1 then
counter_1:setValue(0)
elseif sender.id == "wall_button_2" and counter_1:getValue() == 3 then
counter_1:setValue(2)
elseif sender.id == "wall_button_2" and counter_1:getValue() == 2 then
counter_1:setValue(3)
spawner_2:activate()
elseif sender.id == "wall_button_2" and counter_1:getValue() == 1 then
counter_1:setValue(3)
spawner_2:activate()
elseif sender.id == "wall_button_3" and counter_1:getValue() == 3 then
counter_1:setValue(3)
spawner_3:activate()
elseif sender.id == "wall_button_3" and counter_1:getValue() == 2 then
counter_1:setValue(1)
elseif sender.id == "wall_button_3" and counter_1:getValue() == 1 then
counter_1:setValue(3)
spawner_3:activate()
end
end
counter_1 has initial value = 3
every click on the button should run the script
Can sb halp ?
The code is a bit confusing, so I cleaned it up. The first thing I notice is that there is no code shown to activate the gate once the proper combo is hit. Try this:
function buttonPress(sender)
if sender.id == "wall_button_1" then
if counter_1:getValue() == 1 then
counter_1:setValue(0)
-- open gate here
else
counter_1:setValue(3)
spawner_1:activate()
end
elseif sender.id == "wall_button_2" then
if counter_1:getValue() == 3 then
counter_1:setValue(2)
else
counter_1:setValue(3)
spawner_2:activate()
end
elseif sender.id == "wall_button_3"
if counter_1:getValue() == 2 then
counter_1:setValue(1)
else
counter_1:setValue(3)
spawner_3:activate()
end
end
end
And you will probably want to include code so once the gate is open, the buttons do not continue to activate the spawners. Something like:
Thanks for the quick reply. Your version is looking better, but problem is still present. Opening gate is not a big deal, i have connector in counter_1 which should open the gate after activation(and this is working - when i toggle proper combination the doors open). The problem is: pushing the button few times in a row have no effect . . . meh. OK, I just realized that my buttons have turned on option "activate once" Problem solved, thanks to Allanius2 for fast respond.