Need help with variables in script

● ARCHIVED · READ-ONLY
Started by verheffen 2 posts View original ↗
  1. Good day, RMers!

    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
    So here's the condition. If Quests[qid][conditions][0] (note: 0 is the variable number) is equal to Quests[qid][conditions][1] (note: 1 being the number of tasks in a quests) then this should turn [qid][conditions][2] to true (note: 2 being true(completed quest) or false(ongoing quest).

    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
    ..I also did the necessary DataManager overwrites and aliasing to save the contents so I could invoke the methods via $game_quest. Now this is where the problem rises. If I create a quest giver event via the editor and do a script call: $game_quest.quest_switch(21), it successfully activates the quest and it appears successfully in the quest log. If I create another event, if completed, will invoke the script call: $game_quest.quest_progress(21) which, in this case, adds 1 to the value of the quest's variable.

    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?
  2. Problem is solved, please close thread.

    I had it update through Scene_Map and it is now working flawlessly.