Hello again. Is there a way to check if a variable has changed by 2 or 3 for example. I have designed a day and night system that runs off variable. When variable minutes reaches this number add on to variable hour. Now I want an event that drops certain items when selected but I want it to once activated it checks to see if the variable hour has changed by 2 if you return it to the state were it will drop the item again. Thanks for any help and I hope this makes sense.
Variable changes
● ARCHIVED · READ-ONLY
-
-
Your explanation is somewhat confusing. What I'm understanding is that you want some event to trigger once every 2 hours, for example? What you'd probably want to do is set an extra variable, "time since last activation". Just have it increase every time the hour (or minutes) variable increase, and have it activate the event if the number of hours (minutes) since the last activation is 2 (120) or greater.
If there are literally hundreds of events like this in your game that each require their own activation-tracking variables, you could set up a page condition that subtracts a "time AT last activation" variable from the current time, and checks whether it's greater than or equal to 2 hours, by using Hime's Custom Page Conditions. -
Below are the 2 methods that need to be aliased to figure out if a change was made or if a variable was retrieved.
Code:Try this script:class Game_Variables... #-------------------------------------------------------------------------- # * Get Variable #-------------------------------------------------------------------------- def [](variable_id) @data[variable_id] || 0 end #-------------------------------------------------------------------------- # * Set Variable #-------------------------------------------------------------------------- def []=(variable_id, value) @data[variable_id] = value on_change endendSpoilerCode:Example usage:#sb:nap_on_set_game_var [utility]=beginScript: Detect Game-Variable/SwitchVersion: 1.00Author: NapoleonAbout:- Adds a method that you can override or alias. The method is then called whenever a game_variable or game_switch was changed.- Note: May drain a bit of performance if certain scripts repeatedly change the value of the game variables each frame.Instructions:- Place below "▼ Materials" but above "▼ Main Process".- Alias (or override) Game_Variables.on_set_variable(var_id, old_value, new_value)Requires:- RPG Maker VX AceTerms of Use:- Attribution 3.0 Unported (CC BY 3.0) [URL="http://creativecommons.org/licenses/by/3.0/Version"]http://creativecommons.org/licenses/by/3.0/Version[/URL] History:1.00 (26 August 2014) - First Release=end$imported ||= {}$imported[:nap_on_set_game_var] = 1.00#===============================================================================# Game Variables#===============================================================================class Game_Variables #----------------------------------------------------------------------------- # []= [ALIAS] #----------------------------------------------------------------------------- alias :nap_detect :[]= def []=(variable_id, value) old_value = @data[variable_id] nap_detect(variable_id, value) on_set(variable_id, old_value, @data[variable_id]) end #----------------------------------------------------------------------------- # On Set Variable [NEW] #----------------------------------------------------------------------------- def on_set(variable_id, old_value, new_value); endend#===============================================================================# Game Switches#===============================================================================class Game_Switches #----------------------------------------------------------------------------- # []= [ALIAS] #----------------------------------------------------------------------------- alias :nap_detect :[]= def []=(switch_id, value) old_value = @data[switch_id] nap_detect(switch_id, value) on_set(switch_id, old_value, @data[switch_id]) end #----------------------------------------------------------------------------- # On Set Variable [NEW] #----------------------------------------------------------------------------- def on_set(switch_id, old_value, new_value); endend#===============================================================================
Code:#sb:nap_on_set_game_var [utility]#===============================================================================# Game Variable Example#===============================================================================class Game_Variables alias nap_sample_on_set on_set def on_set(variable_id, old_value, new_value) nap_sample_on_set(variable_id, old_value, new_value) print "Game-variable change detected: " print "Index: #{variable_id}; old value: #{old_value || 'nil'}, new value: #{new_value}.\n" endend#===============================================================================# Game Switch Example#===============================================================================class Game_Switches alias nap_sample_on_set on_set def on_set(switch_id, old_value, new_value) nap_sample_on_set(switch_id, old_value, new_value) print "Game-switch change detected: " print "Index: #{switch_id}; #{old_value || 'false'} ==> #{new_value}.\n" endend#===============================================================================