So I wanted to try my hand at making an Element script, but I am having a problem. Let me explain:
I created an event that calls
$scene = Scene_Gem.new
So, my scene runs... no problem there. Now, I am expecting certain values to be set when I enter Window_Gems and select the empty index; that is, for the values
@original_gem
and
@new_gem
to remain equaling zero. But, alas, this is not the case... I set
$game_variables[1] = @original_gem
and
$game_variables[2] = @new_gem
to determine the values, and for some reason, I get variable 1 = 9 and variable 2 = 4. I am pasting the script below, and if anyone could fill me in on the problem, that would be awesome! btw... I know the coding is hideous, but it is most definitely a WIP.
module RPG
class Weapon
alias old_initialize initialize
def initialize
old_initialize
@gem_id = 0
end
attr_accessor :gem_id
end
end
module Xx
# {Item_id => [[element_set]]}
Gems = {
32 => [[1]]
}
end
class Scene_Title
alias old_command_new_game command_new_game
def command_new_game
$data_weapons[1].gem_id = 0
old_command_new_game
end
end
class Window_Base < Window
def draw_gem_name(weapon)
self.contents.font.color = normal_color
if weapon.gem_id > 0
self.contents.draw_text(100, 0, 80, 32, weapon.gem_id.to_s)
else
self.contents.draw_text(100, 0, 80, 32, "None")
end
end
end
class Window_EquippedGem < Window_Selectable
def initialize(actor)
super(320, 416, 320, 64)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
self.index = 0
self.active = true
refresh
end
def refresh
self.contents.clear
@data = []
@data.push($data_weapons[@actor.weapon_id])
@item_max = @data.size
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 92, 32, "Gem: ")
draw_gem_name(@data[0])
end
def item
return $data_weapons[@actor.weapon_id].gem_id
end
end
class Window_Weapon < Window_Base
def initialize(actor)
super(0, 416, 320, 64)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
refresh
end
def refresh
self.contents.clear
@data = []
@data.push($data_weapons[@actor.weapon_id])
@item_max = @data.size
self.contents.font.color = system_color
self.contents.draw_text(4, 32 * 0, 92, 32, @actor.name)
draw_item_name(@data[0], 92, 32 * 0)
end
end
class Window_Gems < Window_Selectable
def initialize
super(0, 64, 640, 352)
@column_max = 2
refresh
self.index = -1
self.active = false
end
def item
return @data[self.index]
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 1...$data_items.size
if Xx::Gems.keys.include?(i)
if $game_party.item_number(i) > 0
@data.push($data_items[i])
end
end
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_party.item_number(item.id)
end
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
class Scene_Gem
def initialize(actor_index = 0, equip_index = 0)
@actor_index = actor_index
@equip_index = equip_index
end
def main
@actor = $game_party.actors[@actor_index]
@help_window = Window_Help.new
@weapon_window = Window_Weapon.new(@actor)
@gems_window = Window_Gems.new
@equipped_gem_window = Window_EquippedGem.new(@actor)
refresh
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@help_window.dispose
@equipped_gem_window.dispose
@weapon_window.dispose
@gems_window.dispose
end
def refresh
if @equipped_gem_window.active
@original_gem = $data_weapons[@actor.weapon_id].gem_id
$game_variables[1] = @original_gem
end
if @gems_window.active
@new_gem = @gems_window.item.id
$game_variables[2] = @new_gem
end
end
def update
@help_window.update
@equipped_gem_window.update
@weapon_window.update
@gems_window.update
refresh
if @equipped_gem_window.active
update_equipped_gem
return
end
if @gems_window.active
update_gems
return
end
end
def update_equipped_gem
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
@equipped_gem_window.active = false
@gems_window.active = true
@gems_window.index = 0
return
end
end
def update_gems
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@equipped_gem_window.active = true
@gems_window.active = false
@gems_window.index = -1
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.equip_se)
$data_weapons[@actor.weapon_id].gem_id = @new_gem.id
if $data_weapons[@actor.weapon_id].gem_id != 0
$game_party.gain_item(@original_gem, 1)
$game_party.lose_item(@new_gem, 1)
else
$game_party.lose_item(@new_gem, 1)
end
@equipped_gem_window.active = true
@gems_window.active = false
@gems_window.index = -1
@equipped_gem_window.refresh
@gems_window.refresh
return
end
end
end
So I wanted to try my hand at making an Element script, but I am having a problem. Let me explain:
I created an event that calls
So, my scene runs... no problem there. Now, I am expecting certain values to be set when I enter Window_Gems and select the empty index; that is, for the values
and
to remain equaling zero. But, alas, this is not the case... I set
and
to determine the values, and for some reason, I get variable 1 = 9 and variable 2 = 4. I am pasting the script below, and if anyone could fill me in on the problem, that would be awesome! btw... I know the coding is hideous, but it is most definitely a WIP.
module RPG class Weapon alias old_initialize initialize def initialize old_initialize @gem_id = 0 end attr_accessor :gem_id end end module Xx # {Item_id => [[element_set]]} Gems = { 32 => [[1]] } end class Scene_Title alias old_command_new_game command_new_game def command_new_game $data_weapons[1].gem_id = 0 old_command_new_game end end class Window_Base < Window def draw_gem_name(weapon) self.contents.font.color = normal_color if weapon.gem_id > 0 self.contents.draw_text(100, 0, 80, 32, weapon.gem_id.to_s) else self.contents.draw_text(100, 0, 80, 32, "None") end end end class Window_EquippedGem < Window_Selectable def initialize(actor) super(320, 416, 320, 64) self.contents = Bitmap.new(width - 32, height - 32) @actor = actor self.index = 0 self.active = true refresh end def refresh self.contents.clear @data = [] @data.push($data_weapons[@actor.weapon_id]) @item_max = @data.size self.contents.font.color = system_color self.contents.draw_text(4, 0, 92, 32, "Gem: ") draw_gem_name(@data[0]) end def item return $data_weapons[@actor.weapon_id].gem_id end end class Window_Weapon < Window_Base def initialize(actor) super(0, 416, 320, 64) self.contents = Bitmap.new(width - 32, height - 32) @actor = actor refresh end def refresh self.contents.clear @data = [] @data.push($data_weapons[@actor.weapon_id]) @item_max = @data.size self.contents.font.color = system_color self.contents.draw_text(4, 32 * 0, 92, 32, @actor.name) draw_item_name(@data[0], 92, 32 * 0) end end class Window_Gems < Window_Selectable def initialize super(0, 64, 640, 352) @column_max = 2 refresh self.index = -1 self.active = false end def item return @data[self.index] end def refresh if self.contents != nil self.contents.dispose self.contents = nil end @data = [] for i in 1...$data_items.size if Xx::Gems.keys.include?(i) if $game_party.item_number(i) > 0 @data.push($data_items[i]) end end end @item_max = @data.size if @item_max > 0 self.contents = Bitmap.new(width - 32, row_max * 32) for i in 0...@item_max draw_item(i) end end end def draw_item(index) item = @data[index] case item when RPG::Item number = $game_party.item_number(item.id) end x = 4 + index % 2 * (288 + 32) y = index / 2 * 32 rect = Rect.new(x, y, self.width / @column_max - 32, 32) self.contents.fill_rect(rect, Color.new(0, 0, 0, 0)) bitmap = RPG::Cache.icon(item.icon_name) opacity = self.contents.font.color == normal_color ? 255 : 128 self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity) self.contents.draw_text(x + 28, y, 212, 32, item.name, 0) self.contents.draw_text(x + 240, y, 16, 32, ":", 1) self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2) end def update_help @help_window.set_text(self.item == nil ? "" : self.item.description) end end class Scene_Gem def initialize(actor_index = 0, equip_index = 0) @actor_index = actor_index @equip_index = equip_index end def main @actor = $game_party.actors[@actor_index] @help_window = Window_Help.new @weapon_window = Window_Weapon.new(@actor) @gems_window = Window_Gems.new @equipped_gem_window = Window_EquippedGem.new(@actor) refresh Graphics.transition loop do Graphics.update Input.update update if $scene != self break end end Graphics.freeze @help_window.dispose @equipped_gem_window.dispose @weapon_window.dispose @gems_window.dispose end def refresh if @equipped_gem_window.active @original_gem = $data_weapons[@actor.weapon_id].gem_id $game_variables[1] = @original_gem end if @gems_window.active @new_gem = @gems_window.item.id $game_variables[2] = @new_gem end end def update @help_window.update @equipped_gem_window.update @weapon_window.update @gems_window.update refresh if @equipped_gem_window.active update_equipped_gem return end if @gems_window.active update_gems return end end def update_equipped_gem if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) $scene = Scene_Map.new return end if Input.trigger?(Input::C) $game_system.se_play($data_system.decision_se) @equipped_gem_window.active = false @gems_window.active = true @gems_window.index = 0 return end end def update_gems if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) @equipped_gem_window.active = true @gems_window.active = false @gems_window.index = -1 return end if Input.trigger?(Input::C) $game_system.se_play($data_system.equip_se) $data_weapons[@actor.weapon_id].gem_id = @new_gem.id if $data_weapons[@actor.weapon_id].gem_id != 0 $game_party.gain_item(@original_gem, 1) $game_party.lose_item(@new_gem, 1) else $game_party.lose_item(@new_gem, 1) end @equipped_gem_window.active = true @gems_window.active = false @gems_window.index = -1 @equipped_gem_window.refresh @gems_window.refresh return end end endShare this post
Link to post
Share on other sites