I am having a problem comprehending how variables work. In my case, I am creating a quest log script which also automates quest activation - but it's really simple.
First let me present the simple module I created (wasn't able to update the instructions though):
Spoiler
module HSBX module Quest_Log QUEST_HEADER_TEXT = "HSBX Quest Log" QUEST_LOG_VER = "Ver. 0.0.2-pre-alpha" QUEST_DESCCOM_Y = 72 #========================================================================== Quests = { #========================================================================== #-------------------------------------------------------------------------- # Instructions: #-------------------------------------------------------------------------- # * You can add any number of quests, just make sure you follow the correct # format and you are set. Setting the via events will make this work. # # You can call a quest via: # # quest_gain:)qswitch) # where qswitch is the specified switch number you # # entered in :qswitch # # If you are done with the quest just call the script again. # # qid = Quest ID # qswitch = Switch to turn on/off a quest # qtitle = Title of the quest # qstatus = If quest is done, set to true. Otherwise, set it to false. # qdesc = Description of quest # qreq[n] = Requirements for quest completion # #-------------------------------------------------------------------------- 0 => { :qswitch => 21, :qtitle => "First Quest", :qdesc => "Hello there!", :qreq1 => "Kill 2 Slimes", :qreq2 => "", :qreq3 => "", :qreq4 => "", :qcondition => [21, 4, false], }, 1 => { :qswitch => 22, :qtitle => "Second Quest", :qdesc => "Bye for now!", :qreq1 => "Talk to someone", :qreq2 => "Return to the village", :qreq3 => "", :qreq4 => "", :qcondition => [22, 10, false], }, 2 => { :qswitch => 23, :qtitle => "Third Quest", :qdesc => "I'm back!", :qreq1 => "Walk 50 steps", :qreq2 => "", :qreq3 => "", :qreq4 => "", :qcondition => [23, 20, false], }, #========================================================================== } endend
For this to work, I created a Game_Quest class:
Spoiler
#==============================================================================# ** Game_Quest#------------------------------------------------------------------------------# Class that handle quests.#==============================================================================class Game_Quest include HSBX::Quest_Log #---------------------------------------------------------------------------- # * Public Instance Variables #---------------------------------------------------------------------------- attr_accessor :quest_switch attr_accessor :check_quests attr_accessor :quest_progress attr_accessor :quest_complete attr_accessor :check_complete #---------------------------------------------------------------------------- # * Initialize quests #---------------------------------------------------------------------------- def initialize set_var end #---------------------------------------------------------------------------- # * Set variables #---------------------------------------------------------------------------- def set_var Quests.each_key do |key| var = Quests[key][:qcondition][0] var_max = Quests[key][:qcondition][1] $game_variables[var] = var_max end end #---------------------------------------------------------------------------- # * Method for activating a quest #---------------------------------------------------------------------------- def quest_switch(switch) if $game_switches[switch] == true # When ON $game_switches[switch] = false elsif $game_switches[switch] == false # When OFF $game_switches[switch] = true end end #---------------------------------------------------------------------------- # * Quest progression #---------------------------------------------------------------------------- def quest_progress(qid) if $game_variables[Quests[qid][:qcondition][0]] != Quests[qid][:qcondition][1] $game_variables[Quests[qid][:qcondition][0]] -= 1 unless $game_variables[Quests[qid][:qcondition][0]] == 0 else Quests[qid][:qcondition][2] = true end end #---------------------------------------------------------------------------- # * Checks Quest Flag | Debugging purposes #---------------------------------------------------------------------------- def check_complete(qid) p(Quests[qid][:qcondition][2]) endend
For example, I activated the first quest $game_switches[21] and complete a task, this adds 1 to $game_variables[21] UNTIL it reaches its max which is Quests[qid][:qcondition][1], in this case 4. But whenever variable[21] reaches 4, it does not set the flag to true. I need to complete another task for it to set to true. So this makes it 5 tasks instead of 4.
Do I have to add an update method to this?