Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Optimisable..?

I got a quest scene script from the forum, but I kinda optimized it.
However, I'm wondering if this part could be optimized too somehow, cause I'm like coding 400+ quests.

Code:
    s30 = Quest::Names[30]
    s31 = Quest::Names[31]
    $cmd_window = Window_Command.new(205, [s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28, s29, s30, s31])

So it will look something like?;

Code:
    s1..s400 = Quest::Names[1..400]
    $cmd_window = Window_Command.new(205, [s1..400])

When other variables are calling the module Quest i just used this in the array instead (code below), and deleted all those unnessecary lines of script. However, for the actual command window I don't have a clue.

Code:
[$cmd_window.index + 1]

I would like to know because if this can be optimized I don't have to type this all out...  :dead:

Thanks in advance.  :shades:
 

khmp

Sponsor

What does the Quest module look like? Any reason why the Command Window is global?

If Names is a Hash meaning its arranged like this:
Code:
module Quest
  Names = { 0 => 'Quest 1', 1 => 'Quest 2', ... }
end
Then in the command window's initialization line you can do this:
Code:
$cmd_window = Window_Command.new(205, Quest::Names.values)

However if Name is an Array meaning its arranged like this:
Code:
module Quest
  Names = ['Quest 1', 'Quest 2', ...]
end
Then in the command window's initialization line you can do this:
Code:
$cmd_window = Window_Command.new(205, Quest::Names)

I have no idea what you are trying to accomplish in that next part. Does that get the current quest name? I don't know.

[$cmd_window.index + 1] What is this line supposed to do?
 
EDIT : I did Quest::Names.values, however the whole command window gets messed up. The 27th quest of my list is the first quest in-game right now :crazy:....

Sorry about not being quit detailed.

1) I don't know why the command window is a global variable, the creator of the script made it so. :p

2) It's a Hash.

Now, for the [$cmd_window.index + 1], i'll explain that...

When I Copy/Pasted the script it was like this (first code below).

Code:
  def update_commands
    case $cmd_window.index
    when 0 
      @info = Quest::Info[1]
      @info2 = Quest::Info2[1]
      @info3 = Quest::Info3[1]
      @info4 = Quest::Info4[1]
      @info5 = Quest::Info5[1]
      @info6 = Quest::Info6[1]
      @info7 = Quest::Info7[1]
      @lvreq = Quest::Lvreq[1]
      @start = Quest::Start[1]
      @switch1 = Quest::Start_Switch[1]
      @switch2 = Quest::End_Switch[1]
      refresh
    when 1
      @info = Quest::Info[2]
      @info2 = Quest::Info2[2]
      @info3 = Quest::Info3[2]
      @info4 = Quest::Info4[2]
      @info5 = Quest::Info5[2]
      @info6 = Quest::Info6[2]
      @info7 = Quest::Info7[2]
      @lvreq = Quest::Lvreq[2]
      @start = Quest::Start[2]
      @switch1 = Quest::Start_Switch[2]
      @switch2 = Quest::End_Switch[2]
      refresh
    end
end

The code above is only to make 2 quests get their specific info.

So I made it into this;

Code:
  def update_commands
      @info = Quest::Info[$cmd_window.index + 1]
      @info2 = Quest::Info2[$cmd_window.index + 1]
      @info3 = Quest::Info3[$cmd_window.index + 1]
      @info4 = Quest::Info4[$cmd_window.index + 1]
      @info5 = Quest::Info5[$cmd_window.index + 1]
      @info6 = Quest::Info6[$cmd_window.index + 1]
      @info7 = Quest::Info7[$cmd_window.index + 1]
      @lvreq = Quest::Lvreq[$cmd_window.index + 1]
      @start = Quest::Start[$cmd_window.index + 1]
      @switch1 = Quest::Start_Switch[$cmd_window.index + 1]
      @switch2 = Quest::End_Switch[$cmd_window.index + 1]
      refresh
    end

Which works just perfect.

To answer you're question;

It doesn't get the quest name but it does get all the other info.
Because when the cursor is on quest 1 the game will say that $cmd_window.index = 0... so for that, $cmd_window.index + 1, so that i gets the info for quest 1. But I guess you're a advanced scripted so I don't have to explain it to you..  :tongue:



Thank you for your reply and I'll check what I can do with it. :D
 

khmp

Sponsor

If this update_commands method is used to redraw a window. You'll need to mess with the refresh method to get the Quest::Name to draw. To save it to a public instance variable:
Code:
@quest_name = Quest::Names[$cmd_window.index + 1]

Then in the refresh method to draw the quest name you would have a line like this:
Code:
self.contents.draw_text(x, y, width, 32, @quest_name) unless @quest_name.nil?

But I'd need to see more of the script to actually know how it works for sure.
 
I did Quest::Names.values but the command window got messed up. It now shows the 27th quest as first in the command window and with quest 1's info. :\

Anyway, the update_commands don't (re)draw any windows. Every variable in update_commands just draws text (info) for every specific quest.

Sorry but, the majority of your post, I don't quit understand. How does self.contents.draw_text, have to do with optimizing a command window?

Anyways;

Code:
    s1 = Quest::Names[1]
    s2 = Quest::Names[2]
    s3 = Quest::Names[3]
    s4 = Quest::Names[4]
    s5 = Quest::Names[5]
    s6 = Quest::Names[6]
    s7 = Quest::Names[7]
    s8 = Quest::Names[8]
    s9 = Quest::Names[9]
    s10 = Quest::Names[10]
    s11 = Quest::Names[11]
    s12 = Quest::Names[12]
    s13 = Quest::Names[13]
    s14 = Quest::Names[14]
    s15 = Quest::Names[15]
    s16 = Quest::Names[16]
    s17 = Quest::Names[17]
    s18 = Quest::Names[18]
    s19 = Quest::Names[19]
    s20 = Quest::Names[20]
    s21 = Quest::Names[21]
    s22 = Quest::Names[22]
    s23 = Quest::Names[23]
    s24 = Quest::Names[24]
    s25 = Quest::Names[25]
    s26 = Quest::Names[26]
    s27 = Quest::Names[27]
    s28 = Quest::Names[28]
    s29 = Quest::Names[29]
    s30 = Quest::Names[30]
    s31 = Quest::Names[31]
  $cmd_window = Window_Command.new(205, [s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28, s29, s30, s31])

I made that ugly code into :

Code:
    $cmd_window = Window_Command.new(205, Quest::Names.values)

It kinda works thank you for that but, as i stated earlier, the 27th quest shows as first in the command window with the 1st quest it's info (then the 28th, 29th, 30th, 31th, 32th, 1st, 2nd quest etc.). Any idea how that weird arrangement is happening?

The Script, well, 2/3 of it.

Code:
module Quest
  # Quest Names
  Names = {1 => "Sera's Mirror", 
  2 => "Roger's Apple", 
  3 => "Sen's Diner Menu", 
  4 => "Todd's How To Hunt", 
  5 => "Sam's Suggestion", 
  6 => "Sam's Advice",
  7 => "Mai's Training", 
  8 => "Mai's Final Training", 
  9 => "A Letter To Lucas", 
  10 => "Lucas' Reply", 
  11 => "Lucas' Cute Daughter", 
  12 => "Pio And The Recycling", 
  13 => "Bigg's Collection Of Items", 
  14 => "Here Little Piggy", 
  15 => "Rain's Maple Quiz",
  16 => "To Lith Harbor",
  17 => "A Lesson On Job Advancement",
  18 => "The Path Of Warrior",
  19 => "The Path Of Bowman",
  20 => "The Path Of Thief",
  21 => "The Path Of Magician",
  22 => "Graham Cracked",
  23 => "Nella's Dream",
  24 => "Fanzy's Red Furball",
  25 => "Icarus Is Bored",
  26 => "Visiting Mr.Spot",
  27 => "Beauty Or Beast",
  28 => "Eurek The Alchemist",
  29 => "Marr The Fairy",
  30 => "I Need To Find My Daughter",
  31 => "Interstellar Relics"}
end
#----Scene_Quests--------------------------------------------------------------
class Scene_Quests
  def initialize(menu_index = 0)
    @menu_index = menu_index
    # * Update the number of quests you wish to have in the quest window here.
    #@quests = 31
  end
  def main
 #   if @quests == 31
    $cmd_window = Window_Command.new(205, Quest::Names.values)#[s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28, s29, s30, s31])
 #   end
    $cmd_window.index = @menu_index
    $cmd_window.y = 50
    $cmd_window.height = 420
    $cmd_window.width = 230
    $cmd_window.opacity = 0
    $cmd_window.back_opacity = 0
    $cmd_window.contents.font.color = Color.new(0, 0, 0, 255)
    @quest_bck = Sprite.new
    @quest_bck.bitmap = RPG::Cache.picture("Quest/Quest.bck")
    @quest_bck.x = 0
    @quest_bck.y = 0
    @quests_status = Window_QuestsStatus.new
    @quests_window = Window_Quests.new
    @reward_window = Window_Reward.new
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    $cmd_window.dispose
    @quests_status.dispose
    @quests_window.dispose
    @reward_window.dispose
    @quest_bck.dispose
    @quest_bck.bitmap.dispose
  end
  def update
    @quests_window.update
    @quests_status.update
    @reward_window.update
    $cmd_window.update
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
    end
  end
end
#----Window_QuestsStatus-------------------------------------------------------
class Window_QuestsStatus < Window_Base
  def initialize
    super(250, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Verdana"
    self.contents.font.size = 10
    self.contents.font.bold = true
    self.opacity = 0
    self.back_opacity = 0
    update_commands
  end
   def update
    if $cmd_window.active
      self.contents.clear
      update_commands
      return
      end
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @names.dispose
  end
  
  def update_commands
    #case $cmd_window.index
    #when 0 
      @names = Quest::Names[$cmd_window.index + 1]
      refresh
      return
    end
  
  def refresh
    self.contents.font.color = system_color
    self.contents.draw_text(25, -181, 640, 480, @names.to_s)
  end
end
class Window_Quests < Window_Selectable
  def initialize
    super(250, 60, 410, 340)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Verdana"
    self.contents.font.size = 10
    self.contents.font.bold = false
    self.opacity = 0
    self.back_opacity = 0
    @switch1 = Quest::Start_Switch[1]
    @switch2 = Quest::End_Switch[1]
    @actor = $game_party.actors[0]
    @lvreq = 1
    refresh
  end
  def update
    if $cmd_window.active
      self.contents.clear
      update_commands
      return
    end
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @info.dispose
    @info2.dispose
    @info3.dispose
    @info4.dispose
    @info5.dispose
    @info6.dispose
    @info7.dispose
    @lvreq.dispose
    @switch1.dispose
    @switch2.dispose
    @start.dispose
    @status.dispose
    @status.bitmap.dispose
  end
  def update_commands
      @info = Quest::Info[$cmd_window.index + 1]
      @info2 = Quest::Info2[$cmd_window.index + 1]
      @info3 = Quest::Info3[$cmd_window.index + 1]
      @info4 = Quest::Info4[$cmd_window.index + 1]
      @info5 = Quest::Info5[$cmd_window.index + 1]
      @info6 = Quest::Info6[$cmd_window.index + 1]
      @info7 = Quest::Info7[$cmd_window.index + 1]
      @lvreq = Quest::Lvreq[$cmd_window.index + 1]
      @start = Quest::Start[$cmd_window.index + 1]
      @switch1 = Quest::Start_Switch[$cmd_window.index + 1]
      @switch2 = Quest::End_Switch[$cmd_window.index + 1]
      refresh
    end
    
  def refresh
    self.contents.font.bold = true
    self.contents.font.color = system_color
    self.contents.draw_text(10, 30, 320, 32, "Quest Description :")
     self.contents.font.bold = false
    self.contents.font.color = Color.new(0, 0, 0, 255)
    if $game_switches[@switch1] == false
    self.contents.draw_text(10, 52, 500, 32, @info.to_s)
    self.contents.draw_text(10, 74, 500, 32, @info2.to_s)
    elsif $game_switches[@switch1] == true and $game_switches[@switch2] == false
    self.contents.draw_text(10, 52, 500, 32, @info3.to_s)
    self.contents.draw_text(10, 74, 500, 32, @info4.to_s)
    self.contents.draw_text(10, 96, 500, 32, @info5.to_s)
    elsif $game_switches[@switch2] == true
    self.contents.draw_text(10, 52, 500, 32, @info6.to_s)
    self.contents.draw_text(10, 74, 500, 32, @info7.to_s)
    end
    self.contents.font.bold = true
    self.contents.font.color = system_color
    self.contents.draw_text(10, 126, 320, 32, "Starting Location :")
    self.contents.font.bold = false
    self.contents.font.color = Color.new(0, 0, 0, 255)
    self.contents.draw_text(10, 148, 500, 32, @start.to_s)
    self.contents.font.bold = true
    self.contents.font.color = system_color
    self.contents.draw_text(10, 178, 320, 32,"Quest Status :")
    self.contents.draw_text(10, 220, 320, 32,"Level Requirement :")
    self.contents.font.bold = false
    self.contents.font.color = Color.new(0, 0, 0, 255)
    if @lvreq == 1
    self.contents.draw_text(10, 245, 320, 32,"There is no level requirement for this quest.")
    else
    if @lvreq > 99
    bitmap = RPG::Cache.icon("Level - (#{@lvreq})")
    self.contents.blt(107, 272, bitmap, Rect.new(0, 0, 100, 100))
    self.contents.draw_text(10, 245, 320, 32,"You have to be level")
    self.contents.draw_text(145, 245, 320, 32,"or higher to do this quest.")
    elsif @lvreq > 9
    bitmap = RPG::Cache.icon("Level - (#{@lvreq})")
    self.contents.blt(107, 272, bitmap, Rect.new(0, 0, 100, 100))
    self.contents.draw_text(10, 245, 320, 32,"You have to be level")
    self.contents.draw_text(135, 245, 320, 32,"or higher to do this quest.")
    else
    bitmap = RPG::Cache.icon("Level - (#{@lvreq})")
    self.contents.blt(107, 272, bitmap, Rect.new(0, 0, 100, 100))
    self.contents.draw_text(10, 245, 320, 32,"You have to be level")
    self.contents.draw_text(125, 245, 320, 32,"or higher to do this quest.")
    end
    end
    if $game_switches[@switch1] == false
    self.contents.draw_text(10, 200, 320, 32, "This quest is not started yet.")
    elsif $game_switches[@switch1] == true and $game_switches[@switch2] == false
    self.contents.draw_text(10, 200, 320, 32, "This quest is currently in progress.")
    elsif $game_switches[@switch2] == true 
    self.contents.draw_text(10, 200, 320, 32, "This quest has been completed.")
    end
  end
end
#----Window_Reward-------------------------------------------------------------

class Window_Reward < Window_Base
  
   def initialize
    super(250, 400, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Verdana"
    self.contents.font.size = 10
    self.contents.font.bold = false
    self.opacity = 0
    self.back_opacity = 0
    @reward = Quest::Reward[1]
    @switch2 = Quest::End_Switch[1]
    update_commands
  end
  
  def update
    if $cmd_window.active
      self.contents.clear
      update_commands
      return
      end
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @reward.dispose
  end
  
  def update_commands
    #case $cmd_window.index
    #when 0 
      @reward = Quest::Reward[$cmd_window.index + 1]
      @switch2 = Quest::End_Switch[$cmd_window.index + 1]
      refresh
      return
 end
  
  
  def refresh
    if $game_switches[@switch2] == false
     self.contents.font.bold = true
     self.contents.font.color = system_color
     self.contents.draw_text(-0, -0, 640, 480, "Reward :")
     self.contents.font.bold = false
     self.contents.font.color = Color.new(0, 0, 0, 255)
     self.contents.draw_text(-0, -0, 640, 480, @reward.to_s)
   elsif if $game_switches[@switch2] == true
     self.contents.font.bold = true
     self.contents.font.color = system_color
     self.contents.draw_text(0, 0, 640, 480, "Reward :")
     self.contents.font.bold = false
     self.contents.font.color = Color.new(0, 0, 0, 255)
     self.contents.draw_text(0, 0, 640, 480, @reward.to_s)
     end
   end
 end
end
 

khmp

Sponsor

I thought you said you wanted to draw the Quest Name or something maybe I misread it. Just ignore that if thats not the case.

Anyway Hash objects do not care about order. The idea of hashes are like this. The key acts like a variable in a math problem. The place where the data is kept is the answer to that math problem. In any case we just need to create a temporary array to store the sorted values.

Code:
quest_names = []
for i in 0...Quest::Names.values.size
  quest_names << Quest::Names[i] unless Quest::Names[i].nil?
end
$cmd_window = Window_Command.new(205, quest_names)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top