Advertisement
Double_X

DoubleX RMVXA Variable Pointers v1.01a

Jun 1st, 2015 (edited)
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.00 KB | None | 0 0
  1. #==============================================================================|
  2. #  ** Script Info                                                              |
  3. #------------------------------------------------------------------------------|
  4. #  * Script Name                                                               |
  5. #    DoubleX RMVXA Variable Pointers                                           |
  6. #------------------------------------------------------------------------------|
  7. #  * Functions                                                                 |
  8. #    Lets users set some variables to point to some other variables            |
  9. #------------------------------------------------------------------------------|
  10. #  * Terms Of Use                                                              |
  11. #    You shall keep this script's Script Info part's contents intact           |
  12. #    You shalln't claim that this script is written by anyone other than       |
  13. #    DoubleX or his aliases                                                    |
  14. #    None of the above applies to DoubleX or his aliases                       |
  15. #------------------------------------------------------------------------------|
  16. #  * Prerequisites                                                             |
  17. #    Abilities:                                                                |
  18. #    1. Basic pointer, script call and game variable knowledge                 |
  19. #    2. Little RGSS3 scripting proficiency to fully utilize this script        |
  20. #------------------------------------------------------------------------------|
  21. #  * Instructions                                                              |
  22. #    1. Open the script editor and put this script into an open slot between   |
  23. #       Materials and Main, save to take effect.                               |
  24. #------------------------------------------------------------------------------|
  25. #  * Links                                                                     |
  26. #    Script Usage 101:                                                         |
  27. #    1. forums.rpgmakerweb.com/index.php?/topic/32752-rmvxa-script-usage-101/  |
  28. #    2. rpgmakervxace.net/topic/27475-rmvxa-script-usage-101/                  |
  29. #    This script:                                                              |
  30. #    1. http://pastebin.com/f9rTGXFw                                           |
  31. #    Mentioned Patreon Supporters:                                             |
  32. #    https://www.patreon.com/posts/71738797                                    |
  33. #------------------------------------------------------------------------------|
  34. #  * Authors                                                                   |
  35. #    DoubleX                                                                   |
  36. #------------------------------------------------------------------------------|
  37. #  * Changelog                                                                 |
  38. #    v1.01a(GMT 1300 2-6-2015):                                                |
  39. #    1. Users can set "pointers to pointers to pointers..." for some variables |
  40. #    v1.00a(GMT 1500 1-6-2015):                                                |
  41. #    1. 1st version of this script finished                                    |
  42. #==============================================================================|
  43.  
  44. #==============================================================================|
  45. #  ** Script Call Info                                                         |
  46. #------------------------------------------------------------------------------|
  47. #  * Variable manipulations                                                    |
  48. #    1. $game_variables.var_pointers[var_id] = [pointer_val, chain_flag]       |
  49. #       - Sets the variable with id var_id to point to the variable with id    |
  50. #         pointer_val if pointer_val is an integer greater than 0              |
  51. #       - Sets the variable with id var_id to stop pointing to any variable if |
  52. #         pointer_val isn't an integer or is less than or equal to 0           |
  53. #       - When a variable isn't pointing to any variable and the former's      |
  54. #         being read/written, only it'll be actually read/written              |
  55. #       - When variable A points to variable B with A's chain_flag as false or |
  56. #         B not pointing to any variable, and A's being read/written, only B   |
  57. #         will actually be read/written instead                                |
  58. #       - When variable A points to variable B with A's chain_flag as true and |
  59. #         B pointing to variable C with B's chain flag as false or C not       |
  60. #         pointing to any variable, and A's being read/written, only C will    |
  61. #         actually be read/written instead                                     |
  62. #       - When variable A points to variable B with A's chain_flag as true and |
  63. #         B pointing to variable A with B's chain flag as true, both A and B   |
  64. #         effectively points to their respective selfs instead                 |
  65. #       - When a variable points to itself, it effectively doesn't point to any|
  66. #         variable                                                             |
  67. #    2. $game_variables.var_pointers[var_id][0] =                              |
  68. #       $game_variables.var_pointers[var_id][0].to_s                           |
  69. #       - Deactivates the pointer behavior for variable with id var_id while   |
  70. #         still keeping its pointer record with its chain flag                 |
  71. #    3. $game_variables.var_pointers[var_id][0] =                              |
  72. #       $game_variables.var_pointers[var_id][0].to_i                           |
  73. #       - Activates the pointer behavior for variable with id var_id using its |
  74. #         pointer record with its chain flag                                   |
  75. #==============================================================================|
  76.  
  77. ($doublex_rmvxa ||= {})[:Variable_Pointers] = "v1.01a"
  78.  
  79. #==============================================================================|
  80. #  ** Script Implementations                                                   |
  81. #     You need not edit this part as it's about how this script works          |
  82. #------------------------------------------------------------------------------|
  83. #  * Script Support Info:                                                      |
  84. #    1. Prerequisites                                                          |
  85. #       - Solid understanding of game variables and pointers                   |
  86. #       - Some RGSS3 scripting proficiency to fully comprehend this script     |
  87. #    2. Method documentation                                                   |
  88. #       - The 1st part informs whether the method's rewritten, aliased or new  |
  89. #       - The 2nd part describes what the method does for new methods only     |
  90. #       - The 3rd part describes what the arguments of the method are          |
  91. #       - The 4th part describes how this method works for new methods only,   |
  92. #         and describes the parts added or rewritten for rewritten or aliased  |
  93. #         methods only                                                         |
  94. #       Example:                                                               |
  95. # #----------------------------------------------------------------------------|
  96. # #  Rewrite/Alias/New method: def_name                                        |
  97. # #  - What this method does                                                   |
  98. # #----------------------------------------------------------------------------|
  99. # # *args: What these arguments are                                            |
  100. # def def_name(*args)                                                          |
  101. #   # How this method works                                                    |
  102. #   def_name_code                                                              |
  103. #   #                                                                          |
  104. # end # def_name                                                               |
  105. #------------------------------------------------------------------------------|
  106.  
  107. #------------------------------------------------------------------------------|
  108. #  * Edit class: Game_Variables                                                |
  109. #------------------------------------------------------------------------------|
  110.  
  111. class Game_Variables
  112.  
  113.   #----------------------------------------------------------------------------|
  114.   #  New public instance variable                                              |
  115.   #----------------------------------------------------------------------------|
  116.   attr_reader :var_pointers # Stores the variable pointer records
  117.  
  118.   #----------------------------------------------------------------------------|
  119.   #  Alias method: initialize                                                  |
  120.   #----------------------------------------------------------------------------|
  121.   alias initialize_var_pointers initialize
  122.   def initialize
  123.     initialize_var_pointers
  124.     # Added to store the var_id => [pointer_val, chain_flag] records
  125.     @var_pointers = {}
  126.     #
  127.   end # initialize
  128.  
  129.   #----------------------------------------------------------------------------|
  130.   #  Alias method: []                                                          |
  131.   #----------------------------------------------------------------------------|
  132.   alias get_var_pointers []
  133.   def [](var_id)
  134.     # Rewritten to get the pointed variable instead if it points to a variable
  135.     get_var_pointers(search_var_pointers([var_id]))
  136.     #
  137.   end
  138.  
  139.   #----------------------------------------------------------------------------|
  140.   #  Alias method: []=                                                         |
  141.   #----------------------------------------------------------------------------|
  142.   alias set_var_pointers []=
  143.   def []=(var_id, val)
  144.     # Rewritten to set the pointed variable instead if it points to a variable
  145.     set_var_pointers(search_var_pointers([var_id]), val)
  146.     #
  147.   end
  148.  
  149.   #----------------------------------------------------------------------------|
  150.   #  (v1.01a+)New method: search_var_pointers                                  |
  151.   #  - Returns the destinated id of the variable that is actually pointed to   |
  152.   #----------------------------------------------------------------------------|
  153.   # ids: The array storing the initial variable id as its sole element
  154.   def search_var_pointers(ids)
  155.     while @var_pointers.include?(ids[-1])
  156.       # Stop searching when false chain flag or cycle chaining's detected
  157.       chain = @var_pointers[ids[-1]][1]
  158.       cycle = ids.include?(@var_pointers[ids[-1]][0])
  159.       ids << @var_pointers[ids[-1]][0]
  160.       break unless chain && !cycle
  161.       #
  162.     end
  163.     ids[-1]
  164.   end # search_var_pointers
  165.  
  166. end # Game_Variables
  167.  
  168. #------------------------------------------------------------------------------|
  169.  
  170. #==============================================================================|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement