Page 1 of 1

script problem[SOLVED]

Posted: Sun Jul 06, 2014 1:05 am
by Kaold
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.

Code: Select all

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 ?

Re: script problem

Posted: Sun Jul 06, 2014 7:16 am
by Allanius2
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.

Code: Select all

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:

Code: Select all

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:

Code: Select all

If counter_1:getValue() > 0 then
You can put this line right before the line:

Code: Select all

   if sender.id == "wall_button_1" then
and add another "end" at the end of the function.
Hope this helps. Good luck.

Re: script problem[SOLVED]

Posted: Sun Jul 06, 2014 1:41 pm
by Kaold
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.

Re: script problem[SOLVED]

Posted: Sun Jul 06, 2014 6:59 pm
by Allanius2
You're welcome. Glad I could help.