Activate Switch with a button
#1
Brick 
Hi! I'm using a mini-map that it's triggered by a switch, so I'm trying to turn the switch on and off when pressing a button, however, I don't know much about Ruby and I'm probably missing something (maybe some kind of break to prevent the conditional from looping?)
The code I wrote is as follows:


Code:
if Input.trigger?(Input::L)
if $game_switches[2] = false    
$game_switches[2] = true    
end
if $game_switches[2] = true  
$game_switches[2] = false
end
end


I would appreciate if someone has the time to tell me what I'm doing wrong or missing! Thanks before hand =)
I'm looking for a scripter to help me with my proyect. Need some minor adjustments-modifications and some larger codes. The larger ones will be remunerated :) Thanks beforehand.
Reply }
#2
Try:
Code:
if Input.trigger?(Input::L) && $game_switches[2] = false
  $game_switches[2] = true
end

if Input.trigger?(Input::L) && $game_switches[2] = true
  $game_switches[2] = false
end
Reply }
#3
Hmmm I think that should work but somehow the switch is not being activated (I checked it with F9...)
I'm looking for a scripter to help me with my proyect. Need some minor adjustments-modifications and some larger codes. The larger ones will be remunerated :) Thanks beforehand.
Reply }
#4
oh whoops! (this is why you don't try to script after working for 8 hours) Try this:

Code:
if Input.trigger?(Input::L) && $game_switches[2] = false
  $game_switches[2] = true
  p "switch on!"
elsif Input.trigger?(Input::L) && $game_switches[2] = true
  $game_switches[2] = false
  p "switch off!"
end

remove the print statements once you know it's working. What is probably happening is the first 'if' is satisfied so the switch is set to true, and then since the switch is true the second if statement is run, setting the switch back to false.

That is, if you put your code somewhere where it can run every frame. You did that, right?
Reply }
#5
Hmmmm when I press the button it shows 'switch off' every single time.
I'm looking for a scripter to help me with my proyect. Need some minor adjustments-modifications and some larger codes. The larger ones will be remunerated :) Thanks beforehand.
Reply }
#6
I HATE toggles, I always do them wrong. My last advice is to switch the order of the statements, otherwise I'll have to leave you in the hands of someone else.
Reply }
#7
You can do this REALLY easily with a single event... just "wait for button" then "condition > if on, turn off, if off, turn on" !
Reply }
#8
You need to first check if the button is pressed (regardless of the switch).
THEN... you toggle based on the current switch condition:
Code:
if Input.trigger?(Input::L)
  if $game_switches[2] = false
    p "on"
    $game_switches[2] = true
  else
    p "off"
    $game_switches[2] = false
  end
end
And as MechanicalPen stated, remove the 'p'/print statement lines when you're satified.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   How can i activate switches with rgss computerwizoo7 2 7,398 07-04-2009, 03:01 AM
Last Post: computerwizoo7



Users browsing this thread: 1 Guest(s)