SHARE
TWEET

extended input error

a guest Jun 22nd, 2015 205 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Scene_Test < Scene_Base
  2.  
  3.   def start
  4.     super
  5.   end
  6.  
  7.   def update
  8.     super
  9.     $ctrl.flip_mode if $ctrl.trigger_help
  10.     p($ctrl.key_any?)   # <---------------------------------this produces  key.trigger? == true  every other frame when "key.press?"
  11.   end
  12.  
  13.  
  14.  
  15. ###############################
  16. my script using extended input system
  17. ###############################
  18.  
  19. class Game_Input
  20.   attr_reader :up
  21.   attr_reader :down
  22.   attr_reader :left
  23.   attr_reader :right
  24.   attr_reader :up_left
  25.   attr_reader :up_right
  26.   attr_reader :down_left
  27.   attr_reader :down_right
  28.   attr_accessor :pgup                           # page up
  29.   attr_accessor :pgdn                           # page down
  30.   attr_accessor :pglf                           # page left
  31.   attr_accessor :pgrt                           # page right
  32.   attr_accessor :pause                          # toggle pause
  33.   attr_accessor :help                           # toggle help windows etc..
  34.   attr_accessor :ok                             # (ok / attack)
  35.   attr_accessor :cancel                         # (cancel / run)
  36.   attr_accessor :menu                           # (menu / exit menu)
  37.   attr_accessor :ability                        # use equipped (ability / item)
  38.   attr_accessor :wait_time                      # time between input proccessing
  39.  
  40.   attr_accessor :new_assignment                 # temp slot for key binding
  41.  
  42.   def initialize
  43.     @wait_time = 5
  44.     @wait = 0
  45.     @new_assignment = nil
  46.     set_mode(Keyboard)
  47.     @joys = {:up      => :UP,
  48.              :down    => :DOWN,
  49.              :left    => :LEFT,
  50.              :right   => :RIGHT,
  51.              :ok      => :JOY2,
  52.              :cancel  => :JOY3,
  53.              :menu    => :JOY1,
  54.              :ability => :JOY4,       #<- Rename(action, interact, ?...
  55.              :pgup    => :JOY5,
  56.              :pgdn    => :JOY6,
  57.              :pglf    => :JOY7,
  58.              :pgrt    => :JOY8,
  59.              :help    => :JOY9,
  60.              :pause   => :JOY10
  61.     }
  62.     @keys = {:up      => :UP,
  63.              :down    => :DOWN,
  64.              :left    => :LEFT,
  65.              :right   => :RIGHT,
  66.              :ok      => :X,
  67.              :cancel  => :Z,
  68.              :menu    => :S,
  69.              :ability => :A,       #<- Rename(action, interact, ?...
  70.              :pgup    => :PAGE_UP,
  71.              :pgdn    => :PAGE_DOWN,
  72.              :pglf    => :Q,
  73.              :pgrt    => :W,
  74.              :help    => :H,
  75.              :pause   => :SPACE
  76.     }
  77.   end
  78.  
  79.   def update
  80.     @wait -= 1 if @wait > 0
  81.     @wait = @wait_time if ready? && any_input?
  82.   end
  83.  
  84.   def ready?
  85.     @wait == 0
  86.   end
  87.  
  88.   def any_input?
  89.     return true if trigger_up
  90.     return true if trigger_down
  91.     return true if trigger_left
  92.     return true if trigger_right
  93.     return true if trigger_ok
  94.     return true if trigger_cancel
  95.     return true if trigger_menu
  96.     return true if trigger_ability
  97.     return true if trigger_page_up
  98.     return true if trigger_page_down
  99.     return true if trigger_page_left
  100.     return true if trigger_page_right
  101.     return true if trigger_help
  102.     return true if trigger_pause
  103.     return false
  104.   end
  105.    
  106.    
  107.  
  108.   def button
  109.     if @device == Keyboard
  110.       @keys
  111.     else
  112.       @joys
  113.     end
  114.   end
  115.  
  116.   def set_mode(device)
  117.     @device = device
  118.   end
  119.  
  120.   def flip_mode
  121.     @device == Keyboard ? set_mode(Gamepad[1]) : set_mode(Keyboard)
  122.   end
  123.  
  124. #-------------------------------------------------------------------------------
  125. # - BUTTONS (trigger)
  126. #_______________________________________________________________________________
  127.  
  128.   def trigger_up
  129.     @device.trigger?(button[:up])
  130.   end
  131.  
  132.   def trigger_down
  133.     @device.trigger?(button[:down])
  134.   end
  135.  
  136.   def trigger_left
  137.     @device.trigger?(button[:left])
  138.   end
  139.  
  140.   def trigger_right
  141.     @device.trigger?(button[:right])
  142.   end
  143.  
  144.   def trigger_ok
  145.     @device.trigger?(button[:ok])
  146.   end
  147.  
  148.   def trigger_cancel
  149.     @device.trigger?(button[:cancel])
  150.   end
  151.  
  152.   def trigger_menu
  153.     @device.trigger?(button[:menu])
  154.   end
  155.  
  156.   def trigger_ability
  157.     @device.trigger?(button[:ability])
  158.   end
  159.  
  160.   def trigger_page_up
  161.     @device.trigger?(button[:pgup])
  162.   end
  163.  
  164.   def trigger_page_down
  165.     @device.trigger?(button[:pgdn])
  166.   end
  167.  
  168.   def trigger_page_left
  169.     @device.trigger?(button[:pglf])
  170.   end
  171.  
  172.   def trigger_page_right
  173.     @device.trigger?(button[:pgrt])
  174.   end
  175.  
  176.   def trigger_help
  177.     @device.trigger?(button[:help])
  178.   end
  179.  
  180.   def trigger_pause
  181.     @device.trigger?(button[:pause])
  182.   end
  183.  
  184. #-------------------------------------------------------------------------------
  185. # - BUTTONS (press)
  186. #_______________________________________________________________________________
  187.  
  188.   def press_up
  189.     @device.press?(button[:up])
  190.   end
  191.  
  192.   def press_down
  193.     @device.press?(button[:down])
  194.   end
  195.  
  196.   def press_left
  197.     @device.press?(button[:left])
  198.   end
  199.  
  200.   def press_right
  201.     @device.press?(button[:right])
  202.   end
  203.  
  204.   def press_ok
  205.     @device.press?(button[:ok])
  206.   end
  207.  
  208.   def press_cancel
  209.     @device.press?(button[:cancel])
  210.   end
  211.  
  212.   def press_menu
  213.     @device.press?(button[:menu])
  214.   end
  215.  
  216.   def press_ability
  217.     @device.press?(button[:ability])
  218.   end
  219.  
  220.   def press_page_up
  221.     @device.press?(button[:pgup])
  222.   end
  223.  
  224.   def press_page_down
  225.     @device.press?(button[:pgdn])
  226.   end
  227.  
  228.   def press_page_left
  229.     @device.press?(button[:pglf])
  230.   end
  231.  
  232.   def press_page_right
  233.     @device.press?(button[:pgrt])
  234.   end
  235.  
  236.   def press_help
  237.     @device.press?(button[:help])
  238.   end
  239.  
  240.   def press_pause
  241.     @device.press?(button[:pause])
  242.   end
  243.  
  244. #-------------------------------------------------------------------------------
  245. # - BUTTONS (repeat)
  246. #_______________________________________________________________________________
  247.  
  248.   def repeat_up
  249.     @device.repeat?(button[:up])
  250.   end
  251.  
  252.   def repeat_down
  253.     @device.repeat?(button[:down])
  254.   end
  255.  
  256.   def repeat_left
  257.     @device.repeat?(button[:left])
  258.   end
  259.  
  260.   def repeat_right
  261.     @device.repeat?(button[:right])
  262.   end
  263.  
  264.   def repeat_ok
  265.     @device.repeat?(button[:ok])
  266.   end
  267.  
  268.   def repeat_cancel
  269.     @device.repeat?(button[:cancel])
  270.   end
  271.  
  272.   def repeat_menu
  273.     @device.repeat?(button[:menu])
  274.   end
  275.  
  276.   def repeat_ability
  277.     @device.repeat?(button[:ability])
  278.   end
  279.  
  280.   def repeat_page_up
  281.     @device.repeat?(button[:pgup])
  282.   end
  283.  
  284.   def repeat_page_down
  285.     @device.repeat?(button[:pgdn])
  286.   end
  287.  
  288.   def repeat_page_left
  289.     @device.repeat?(button[:pglf])
  290.   end
  291.  
  292.   def repeat_page_right
  293.     @device.repeat?(button[:pgrt])
  294.   end
  295.  
  296.   def repeat_help
  297.     @device.repeat?(button[:help])
  298.   end
  299.  
  300.   def repeat_pause
  301.     @device.repeat?(button[:pause])
  302.   end
  303.  
  304. #-------------------------------------------------------------------------------
  305. # - BUTTONS (release)
  306. #_______________________________________________________________________________
  307.  
  308.   def release_up
  309.     @device.release?(button[:up])
  310.   end
  311.  
  312.   def release_down
  313.     @device.release?(button[:down])
  314.   end
  315.  
  316.   def release_left
  317.     @device.release?(button[:left])
  318.   end
  319.  
  320.   def release_right
  321.     @device.release?(button[:right])
  322.   end
  323.  
  324.   def release_ok
  325.     @device.release?(button[:ok])
  326.   end
  327.  
  328.   def release_cancel
  329.     @device.release?(button[:cancel])
  330.   end
  331.  
  332.   def release_menu
  333.     @device.release?(button[:menu])
  334.   end
  335.  
  336.   def release_ability
  337.     @device.release?(button[:ability])
  338.   end
  339.  
  340.   def release_page_up
  341.     @device.release?(button[:pgup])
  342.   end
  343.  
  344.   def release_page_down
  345.     @device.release?(button[:pgdn])
  346.   end
  347.  
  348.   def release_page_left
  349.     @device.release?(button[:pglf])
  350.   end
  351.  
  352.   def release_page_right
  353.     @device.release?(button[:pgrt])
  354.   end
  355.  
  356.   def release_help
  357.     @device.release?(button[:help])
  358.   end
  359.  
  360.   def release_pause
  361.     @device.release?(button[:pause])
  362.   end
  363.  
  364.   def key_any?
  365.     key_trigs = []
  366.     key_trigs << :ok      if @device.trigger?(button[:ok])
  367.     key_trigs << :cancel  if @device.trigger?(button[:cancel])
  368.     key_trigs << :menu    if @device.trigger?(button[:menu])
  369.     key_trigs << :ability if @device.trigger?(button[:ability])
  370.     key_trigs << :pgup    if @device.trigger?(button[:pgup])
  371.     key_trigs << :pgdn    if @device.trigger?(button[:pgdn])
  372.     key_trigs << :pglf    if @device.trigger?(button[:pglf])
  373.     key_trigs << :pgrt    if @device.trigger?(button[:pgrt])
  374.     key_trigs << :help    if @device.trigger?(button[:help])
  375.     key_trigs << :pause   if @device.trigger?(button[:pause])
  376.     key_trigs
  377.   end
  378. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top