Posts: 44
Threads: 10
Joined: Dec 2012
06-18-2013, 07:16 PM
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.
Posts: 422
Threads: 23
Joined: Aug 2011
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
Posts: 44
Threads: 10
Joined: Dec 2012
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.
Posts: 422
Threads: 23
Joined: Aug 2011
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?
Posts: 44
Threads: 10
Joined: Dec 2012
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.
Posts: 422
Threads: 23
Joined: Aug 2011
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.
Posts: 2,507
Threads: 75
Joined: Dec 2010
You can do this REALLY easily with a single event... just "wait for button" then "condition > if on, turn off, if off, turn on" !
Posts: 11,229
Threads: 648
Joined: May 2009
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...)
Above are clickable links