Hey guys. I'm writing a script where you cycle through a list of possible targets with the [Q] and [W] keys. However, I'm having a bit of a problem, because when I so much as look at [Q], it cycles through the whole list. The problem is that the script only detects if the key is down, and doesn't wait for it to be released before detecting again.
I was wondering if there was a way to still have it so that it cycles through the list when the key is pushed down, but then wait for it to be released after before taking another reading.
I'd also like to know how RPGMakerXP does this with the Inventory screen. The game goes to the inventory screen immediately when [Esc] is pressed, but if you keep it held down it doesn't go back to the map screen. It waits for you to release the [Esc] key before it will allow the detection to take you back to the Map Screen. I tried looking at the scripts and there doesn't seem any specific way it does this. Is it because it changes scene in between which somehow resets the detection?
Here's the method that I'm having the issues with.
I was wondering if there was a way to still have it so that it cycles through the list when the key is pushed down, but then wait for it to be released after before taking another reading.
I'd also like to know how RPGMakerXP does this with the Inventory screen. The game goes to the inventory screen immediately when [Esc] is pressed, but if you keep it held down it doesn't go back to the map screen. It waits for you to release the [Esc] key before it will allow the detection to take you back to the Map Screen. I tried looking at the scripts and there doesn't seem any specific way it does this. Is it because it changes scene in between which somehow resets the detection?
Here's the method that I'm having the issues with.
Code:
#--------------------------------------------------------------------------
# * Cycle
#--------------------------------------------------------------------------
def VoodooDoll.cycle
# Cycle Forward
if (Input.press?(Input::R))
if (@cur >= @targets.length-1)
@cur = 0
else
@cur += 1
end
$game_player.center(@targets[@cur].x, @targets[@cur].y)
Input.update
# Cycle Backward
elsif (Input.press?(Input::L))
if (@cur <= 0)
@cur = @targets.length-1
else
@cur -= 1
end
$game_player.center(@targets[@cur].x, @targets[@cur].y)
Input.update
# Confirm
elsif (Input.press?(Input::C))
$game_player.moveto(@targets[@cur].x, @targets[@cur].y)
@mode = 1
# Cancel
elsif (Input.press?(Input::B))
$game_player.center($game_player.x, $game_player.y)
@mode = 0
end
end