Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: DarK_Camper on June 17, 2014, 06:00:53 am

Title: [RESOLVED][XP] Failure to get $game_actors[1].armor1_id
Post by: DarK_Camper on June 17, 2014, 06:00:53 am
I have a bit of a problem where I presume armor1_id is not initializing properly.
The problem is when I open a menu_scene and press the button on index 1, the game_variables[12] doesn't update to the new one.

If this is too vague I'm sorry.  D:


 ...

 def initialize(menu_index=0)
   @menu_index = menu_index
   @actor = $game_actors[1]
   @scweapon = @actor.weapon_id
   @scarmor = @actor.armor1_id #I believe the problem originates here.
 end

 ...

 def update_sc_command
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     $scene = Scene_Map.new
     return
   end
   if Input.trigger?(Input::C)
     case @swordcondense.index
     when 0
       $game_variables[11] = $game_variables[10]
       $game_variables[10] = @scweapon
       @actor.equip(0,0)
     when 1
       $game_variables[13] = $game_variables[12]
       $game_variables[12] = @scarmor # this won't change $game_variables[12] for some reason
       @actor.equip(1,0)
     end
     $game_system.se_play($data_system.decision_se)
     $scene = Scene_Map.new
     return
 end

     ...


Entire script(I;m probably doing a lot of things inefficiently...):
Spoiler: ShowHide

module DARKCAMPER
 module SWORDSUMMON
   SWORDS ={
     #:key => ["name to appear", weapon_id, armor_id, icon, switch]
     :windsword => ["Hertia", 1, 253, "001-Weapon01.png", 25],
     :earthsword => ["Ryzheus", 2, 254, "002-Weapon02.png", 26]
   }
 end
end

class Scene_Swordcondense
 def initialize(menu_index=0)
   @menu_index = menu_index
   @actor = $game_actors[1]
   @scweapon = @actor.weapon_id
   @scarmor = @actor.armor1_id
 end
 
 def main
   # Variable Declarations
   c1 = "Main-hand"
   c2 = "Off-hand"
   
   # Object Declarations and Initializations
   @swordcondense = Window_Command.new(150, [c1, c2])
   @schelp = Window_Schelp.new
   
   # Configuring the window(s)
   @swordcondense.y = 150
   @swordcondense.index = @menu_index
   
   #Pre-processing
   @spriteset = Spriteset_Map.new
   
   # Processing
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   Graphics.freeze
   @swordcondense.dispose
   @schelp.dispose
   @spriteset.dispose
 end
 
 def sc_return(id)
   case id
   # Weapons
   when 1 then return "Hertia"
   when 2 then return "Ryzheus"
   when 3 then return "Fenix"
   when 4 then return "Elena"
   # Armors
   when 253 then return "Hertia"
   when 254 then return "Ryzheus"
   when 255 then return "Fenix"
   when 256 then return "Elena"
   # else
   else return "None equipped."
   end
 end
 
 #Update Methods
 def update
   @swordcondense.update
   sc_text = ""
   
   case @swordcondense.index
   when 0
     sc_text = sc_return(@scweapon)
     @schelp.update(sc_text)
   when 1
     sc_text = sc_return(@scarmor)
     @schelp.update(sc_text)
   end
   
   if @swordcondense.active
     update_sc_command
   end
 end
 
 def update_sc_command
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     $scene = Scene_Map.new
     return
   end
   if Input.trigger?(Input::C)
     case @swordcondense.index
     when 0
       $game_variables[11] = $game_variables[10]
       $game_variables[10] = @scweapon
       @actor.equip(0,0)
     when 1
       $game_variables[13] = $game_variables[12]
       $game_variables[12] = @scarmor
       @actor.equip(1,0)
     end
     $game_system.se_play($data_system.decision_se)
     $scene = Scene_Map.new
     return
   end
 end
end

# Help Window
class Window_Schelp < Window_Base
 def initialize
   super(0,430,640,50)
   self.contents = Bitmap.new(width-32,height-32)
 end
 
 def update(help_text)
   self.contents.clear
   self.contents.draw_text(0, 0, 90, 20, help_text)
 end

end

#Scene_Map Display
class Sword_Condense_Display < Window_Base
 def initialize
   super(604,0,36,100)
   self.opacity = 100
   self.contents = Bitmap.new(width-32,height-32)
   for i in 11..14
     $game_variables[i] = 0
   end
 end
 
 #returns the icon
 def scs_variable_check(variable_id)
   case $game_variables[variable_id]
     when 1
       return DARKCAMPER::SWORDSUMMON::SWORDS[:windsword][3]
     when 2
       return DARKCAMPER::SWORDSUMMON::SWORDS[:earthsword][3]
     else
       return ""
   end
 end
           
 def scs_return_icon_display(slot)
   case slot
     when 1
       return scs_variable_check(10)
     when 2
       return scs_variable_check(11)
     when 3
       return scs_variable_check(12)
     when 4
       return scs_variable_check(13)
   end
 end
 
 def refresh
   self.contents.clear
   reset_variables
   draw_scs_icons
 end
 
 def reset_variables
   @scs_file1 = scs_return_icon_display(1)
   @scs_file2 = scs_return_icon_display(2)
   @scs_file3 = scs_return_icon_display(3)
   @scs_file4 = scs_return_icon_display(4)
   
   @scs_slot1 = RPG::Cache.icon(@scs_file1)
   @scs_slot2 = RPG::Cache.icon(@scs_file2)
   @scs_slot3 = RPG::Cache.icon(@scs_file3)
   @scs_slot4 = RPG::Cache.icon(@scs_file4)
 end
 
 def draw_scs_icons
   self.contents.blt(2,2, @scs_slot1, Rect.new(0,0,32, 32))
   self.contents.blt(2,34,@scs_slot2, Rect.new(0,0,32, 32))
   self.contents.blt(2,66,@scs_slot3, Rect.new(0,0,32, 32))
   self.contents.blt(2,98,@scs_slot4, Rect.new(0,0,32, 32))
 end
 
 def update
   if(@scs_file1 != scs_return_icon_display(1) or
     @scs_file2 != scs_return_icon_display(2) or
     @scs_file3 != scs_return_icon_display(3) or
     @scs_file4 != scs_return_icon_display(4)
     ) then refresh end
 end
end

class Scene_Map
 alias dkc_ss_main main
 alias dkc_ss_update update
 def main
   @scs_display = Sword_Condense_Display.new
   dkc_ss_main
   @scs_display.dispose
 end
end
 
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: Soulshaker3 on June 17, 2014, 07:52:48 am
Quote
        @actor.equip(1,0) 


Is your intention to always unequip the equipment that's equiped already? because basicly what you're saying there is  equip in the shield slot with the id 0
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: LiTTleDRAgo on June 17, 2014, 07:58:32 am
"ただのらくがき": ShowHide
module DARKCAMPER
  module SWORDSUMMON
    SWORDS ={
      #:key => ["name to appear", weapon_id, armor_id, icon, switch]
      :windsword => ["Hertia", 1, 253, "001-Weapon01.png", 25],
      :earthsword => ["Ryzheus", 2, 254, "002-Weapon02.png", 26]
      :firesword => ["Fenix", 3, 255, "003-Weapon03.png", 27]
      :watersword => ["Elena", 4, 256, "004-Weapon04.png", 28]
    }
  end
end

class Scene_Swordcondense
  def initialize(menu_index=0)
    @menu_index = menu_index
    @actor = $game_actors[1]
  end
 
  def main
    # Variable Declarations
    c1 = "Main-hand"
    c2 = "Off-hand"
   
    # Object Declarations and Initializations
    @swordcondense = Window_Command.new(150, [c1, c2])
    @schelp = Window_Schelp.new
   
    # Configuring the window(s)
    @swordcondense.y = 150
    @swordcondense.index = @menu_index
   
    #Pre-processing
    @spriteset = Spriteset_Map.new
   
    # Processing
    Graphics.transition
   
    # Looping
    update_objects.each {|s| s.update} while $scene == self
   
    # Dispose
    Graphics.freeze
    all_dispose
  end
 
  def update_objects
    [Graphics, Input, @swordcondense, self]
  end
 
  def all_dispose
    all = instance_variables.map {|s| instance_variable_get("#{s}")}.flatten
    all.delete_if {|s| s.not.respond_to?(:dispose) }
    all.delete_if {|s| s.respond_to?(:disposed?) && s.disposed?}
    all.dispose
  end 
 
  def sc_return(id)
    case id
    # Weapons
    when 1 then return "Hertia"
    when 2 then return "Ryzheus"
    when 3 then return "Fenix"
    when 4 then return "Elena"
    # Armors
    when 253 then return "Hertia"
    when 254 then return "Ryzheus"
    when 255 then return "Fenix"
    when 256 then return "Elena"
    # else
    else return "None equipped."
    end
  end
 
  #Update Methods
  def update
    case @swordcondense.index
    when 0 then @schelp.update(sc_return(@actor.weapon_id))
    when 1 then @schelp.update(sc_return(@actor.armor1_id))
    end
    @swordcondense.active && update_sc_command
  end
 
  def update_sc_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      return
    end
    if Input.trigger?(Input::C)
      # I believe the main problem is in this part, but I don't even
      # understand what are you trying to accomplish here
      case (@actor && @swordcondense.index)
      when 0
        $game_variables[11] = $game_variables[10]
        $game_variables[10] = @actor.weapon_id
        @actor.equip(0,0)
      when 1
        $game_variables[13] = $game_variables[12]
        $game_variables[12] = @actor.armor1_id
        @actor.equip(1,0)
      end
      $game_system.se_play($data_system.decision_se)
      $scene = Scene_Map.new
      return
    end
  end
end

# Help Window
class Window_Schelp < Window_Base
  def initialize
    super(0,430,640,50)
    self.contents = Bitmap.new(width-32,height-32)
  end
 
  def update(help_text)
    self.contents.clear
    self.contents.draw_text(0, 0, 90, 20, help_text)
  end

end

#Scene_Map Display
class Sword_Condense_Display < Window_Base
  def initialize
    super(604,0,36,100)
    self.opacity = 100
    self.contents = Bitmap.new(width-32,height-32)
    for i in 11..14
      $game_variables[i] = 0
    end
  end
 
  #returns the icon
  def scs_variable_check(variable_id)
    case $game_variables[variable_id]
    when 1 then return DARKCAMPER::SWORDSUMMON::SWORDS[:windsword][3]
    when 2 then return DARKCAMPER::SWORDSUMMON::SWORDS[:earthsword][3]
    when 3 then return DARKCAMPER::SWORDSUMMON::SWORDS[:firesword][3]
    when 4 then return DARKCAMPER::SWORDSUMMON::SWORDS[:watersword][3]
    end
    return ""
  end
           
  def scs_return_icon_display(slot)
    case slot
    when 1 then return scs_variable_check(10)
    when 2 then return scs_variable_check(11)
    when 3 then return scs_variable_check(12)
    when 4 then return scs_variable_check(13)
    end
  end
 
  def refresh
    self.contents.clear
    reset_variables
    draw_scs_icons
  end
 
  def reset_variables
    @scs_file1 = scs_return_icon_display(1)
    @scs_file2 = scs_return_icon_display(2)
    @scs_file3 = scs_return_icon_display(3)
    @scs_file4 = scs_return_icon_display(4)
   
    @scs_slot1 = RPG::Cache.icon(@scs_file1)
    @scs_slot2 = RPG::Cache.icon(@scs_file2)
    @scs_slot3 = RPG::Cache.icon(@scs_file3)
    @scs_slot4 = RPG::Cache.icon(@scs_file4)
  end
 
  def draw_scs_icons
    self.contents.blt(2,2, @scs_slot1, Rect.new(0,0,32, 32))
    self.contents.blt(2,34,@scs_slot2, Rect.new(0,0,32, 32))
    self.contents.blt(2,66,@scs_slot3, Rect.new(0,0,32, 32))
    self.contents.blt(2,98,@scs_slot4, Rect.new(0,0,32, 32))
  end
 
  def update
    if(@scs_file1 != scs_return_icon_display(1) or
      @scs_file2 != scs_return_icon_display(2) or
      @scs_file3 != scs_return_icon_display(3) or
      @scs_file4 != scs_return_icon_display(4)
      ) then refresh end
  end
end

class Scene_Map
  alias_method :dkc_ss_main,   :main
  alias_method :dkc_ss_update, :update
 
  def main
    dkc_ss_main
    @scs_display && @scs_display.dispose
  end
 
  def update(*args)
    dkc_ss_update(*args)
    @scs_display ||= Sword_Condense_Display.new
    @scs_display.update
  end
end
 



to be honest I don't even understand what are you trying to accomplish
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: DarK_Camper on June 17, 2014, 10:49:07 pm
@soulshaker3
Yea, I intend to store the id of the shield slot in a variable and remove it from being equipped after.

@LiTTleDRAGo
This system was meant to open up a menu showing a choice box of "Mainhand" and "Offhand". Which stores the id of whatever item is in the equip slot(either 0 or 1) in variable 10(when 0) or variable 12(when 1). Though before it stores the id of the wep/armor it passes on its value to variable11(when 0) or variable 13(when 1), after which it will unequip it from the actor. The scene_map is to display the icon of whatever is stored in variables 10-13. >.<

The problem happens when I try to use the system and choose "Offhand". It unequips it properly, but it doesn't store the armor1_id in variable 12. Which is why I'm assuming the problem lies with armor1_id. Though I may be wrong.

Sorry if my code is a mess. D:

Edit: I tried using your code but to no avail(I'm not familiar with the error it was spitting out cause of the dispose method).; I also messed around a bit more with the game and tried to use an event to run the script
$game_variables[12] =  $game_actors[1].armor1_id
and it gave me an error saying "NoMethodError ... undefined method 'armor1_id' for [1]:Array"
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: Soulshaker3 on June 18, 2014, 12:00:49 am
Quote$game_variables[12] =  $game_actors[1].armor1_id


It should be :
$game_variables[12] =  $game_party.actors[0].armor1_id
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: KK20 on June 18, 2014, 01:54:35 am
Quote from: DarK_Camper on June 17, 2014, 10:49:07 pm
$game_variables[12] =  $game_actors[1].armor1_id
and it gave me an error saying "NoMethodError ... undefined method 'armor1_id' for [1]:Array"

I find that curious. $game_actors[1] should definitely return Actor #1 from the database. If it thinks $game_actors[1] is [1], that means something is wrong elsewhere.
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: Soulshaker3 on June 18, 2014, 08:27:22 am
Quote from: KK20 on June 18, 2014, 01:54:35 am
Quote from: DarK_Camper on June 17, 2014, 10:49:07 pm
$game_variables[12] =  $game_actors[1].armor1_id
and it gave me an error saying "NoMethodError ... undefined method 'armor1_id' for [1]:Array"

I find that curious. $game_actors[1] should definitely return Actor #1 from the database. If it thinks $game_actors[1] is [1], that means something is wrong elsewhere.


$game_actors should be initialized in the title screen probably he's missing that KK20?
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: KK20 on June 18, 2014, 02:09:56 pm
That wouldn't be it; it would error saying that [] is an undefined method for nil.
$game_actors, to my guess, would have to look like [nil, [1], [2], [3], ... ] for some unknown reason.
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: DarK_Camper on June 18, 2014, 11:05:31 pm
Here are the scripts I have installed(and are mentioned in order):


Valdred's Pre-title Maps
ForeverZer0's Advanced Title Screen
Mobius Journal
game_guys item storage

Moving windows by Fantasist(pulled from Ryex's CCMS down below)

My own scripts(has the script above along with another one)

Blizz-ABS
-Party HUD Addon
-Secondary Weapon Addon
-Auto-targeting Addon
-Visual Equipment Addon

Blizz's Easy Party Switcher

My Scene_Map(placed here to make use of the input module in Blizz-ABS)

ForeverZer0's Advanced Weather
ForeverZer0's Complete Climate and Time System

Ryex's Collapsing Custom Menu System



I have barely edited the configs of the scripts. Something may have overwritten $game_actors? Though I don't think that's the case. >.> I honestly am so unsure of what's causing the problem that I have no idea what I should try and do to fix it. D:
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: KK20 on June 18, 2014, 11:14:45 pm
Then upload your Scripts.rxdata if you're not sure. None of the scripts found here from CP should be rewriting $game_player. I cannot help you any more at this point since the problem cannot be directly seen.
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: DarK_Camper on June 18, 2014, 11:53:08 pm
Sorry, here:

https://www.firedrive.com/file/5C9059E7A22A2774
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: KK20 on June 19, 2014, 12:57:53 am
Okay, after reading your post again, I understand what went wrong. Your script call in the event looked like this:

$game_variables[12] =  $game_actors
[1].armor1_id

when it should look like this

$game_variables[12] = 
$game_actors[1].armor1_id

Just a side-note, script calls read and execute each line of code at a time. Thus, $game_variables[12] was being loaded with the $game_actors array. You then tried to call the method/variable armor1_id on [1], which makes no sense and errors.

Anyways, I know the problem now. Every time you change to Scene_Map, you're initializing a new Sword_Condense_Display object. Check out your initialize method:

#Scene_Map Display
class Sword_Condense_Display < Window_Base
  def initialize
    super(604,0,36,100)
    self.opacity = 100
    self.contents = Bitmap.new(width-32,height-32)
    for i in 11..14   #<============================= Hello, I'm resetting everything back to 0!
      $game_variables[i] = 0
    end
  end

Variable 12 is being changed properly in your scene, but as soon as you go back to Scene_Map, it gets wiped out back to a 0 again.
Title: Re: [XP] Failure to get $game_actors[1].armor1_id
Post by: DarK_Camper on June 19, 2014, 08:22:34 am
Oh crap, I wonder why I put that there. O_O
It works now! :D :D

Thanks a bunch KK20, soulshaker3, and LiTTleDRAgo.  :bow: