- Joined
- Jun 7, 2013
- Messages
- 1,393
- Reaction score
- 210
- First Language
- English
Ok lets try this one more time
Script Two
What you should see when you launch the window,, in the console, is: GC Move down to 0GC2, the console should update and display GC2. But it does not.
If we pay attention to Scene_Currency, in the create_description_window method we see that I am telling window to populate data based on the current item in the currency_list:
def create_description_window @currency_description = Currency_Description.new(@currency_list.width, 0, Graphics.width - @currency_list.width, Graphics.height) @currency_description.data = @currency_list.item endWe see that, in the Currency_Description class, we have a method called:
this updates to tell the console: you have selected GC. now move the cursor down and you don't see the next item in the list in the console: GC2, when you should. why? because I am telling it to update based on: @currency_description.data = @currency_list.itemOr at least I think I am telling it to.
Does this make better sense?
- Run these scripts - do not modify them in any way, run them in a new game
- Create an event and use: call_sample to open the window
- MAKE SURE YOU HAVE THE CONSOLE OPEN
#==============================================================================# ** DataManager#------------------------------------------------------------------------------# This is your customization module where you give your new currency a name# and set it's max value.#==============================================================================module CURR CURR_HASH = { 'GC' => { :full_name => 'Guild Currency', :max => 9999, :description => 'Example Stuffs', }, 'GC2' => { :full_name => 'Guild Currency', :max => 9999, :description => 'Example Stuffs', }, } MENU_VOCAB = 'Currencies' MENU_ENABLED = true end#==============================================================================# ** DataManager#------------------------------------------------------------------------------# This module manages the database and game objects. Almost all of the # global variables used by the game are initialized by this module.#==============================================================================class << DataManager #-------------------------------------------------------------------------- # * Create Game Objects #-------------------------------------------------------------------------- alias kalacious_currency_game_objects create_game_objects def create_game_objects kalacious_currency_game_objects $kc_currency = Game_Currency.new endendclass Game_Currency attr_reader :currency def initialize @currencies = [] create end def create CURR::CURR_HASH.each do |key, value| currency = Create_CurrencyObject.new(key, value[:full_name], value[:max], value[:description], 0) @currencies.push(currency) end end def currencies @currencies end def currency(curr_vocab) if @currencies.any? @currencies.each do |currency| if currency.curr_sym == curr_vocab return currency end end end end def increase(curr_vocab, value) if @currencies.any? @currencies.each do |currency| if currency.curr_sym == curr_vocab currency.value = [[currency.value + value, 0].max, currency.max].min end end end end def decrease(curr_vocab, value) if @currencies.any? @currencies.each do |currency| if currency.curr_sym == curr_vocab increase(curr_vocab, -value) end end end end def set(curr_vocab, value) if @currencies.any? @currencies.each do |currency| if currency.curr_sym == curr_vocab currency.value = [[value, 0].max, currency.max].min end end end end def value(curr_vocab) if @currencies.any? @currencies.each do |currency| if currency.curr_sym == curr_vocab return currency.value end end end end def delete(curr_vocab) @currencies.delete_if {|x, *_| x == curr_vocab } end endclass Create_CurrencyObject attr_reader :curr_sym attr_reader :full_name attr_reader :max attr_reader :description attr_accessor :value def initialize(curr_sym, full_name, max, description, value = 0) @curr_sym = curr_sym @full_name = full_name @max = max @description = description @value = value end end
class Game_Interpreter def call_sample SceneManager.call(Scene_Currencies) endend class List_Currencies < Window_Selectable def initialize(x, y, width, height) super @data = [] activate refresh end def col_max return 1 end def item_max @data ? @data.size : 1 end def enable?(item) true end def item @data && index >= 0 ? @data[index] : nil end def draw_item(index) currency = @data[index] if currency rect = item_rect_for_text(index) draw_text(rect, currency.value.to_s+currency.curr_sym) end end def make_item_list @data = $kc_currency.currencies end def refresh make_item_list create_contents draw_all_items end end class Currency_Description < Window_Base def initialize(x, y, width, height) super end def data=(index) puts index.curr_sym return if @content == index @content = index refresh end def refresh contents.clear create_contents return if @content end end class Scene_Currencies < Scene_MenuBase def start super create_currencies_window create_description_window end def create_currencies_window @currency_list = List_Currencies.new(0, 0, 150, Graphics.height) @currency_list.select(0) end def create_description_window @currency_description = Currency_Description.new(@currency_list.width, 0, Graphics.width - @currency_list.width, Graphics.height) @currency_description.data = @currency_list.item end def update super if Input.trigger?
SceneManager.return end end end
If we pay attention to Scene_Currency, in the create_description_window method we see that I am telling window to populate data based on the current item in the currency_list:
def create_description_window @currency_description = Currency_Description.new(@currency_list.width, 0, Graphics.width - @currency_list.width, Graphics.height) @currency_description.data = @currency_list.item endWe see that, in the Currency_Description class, we have a method called:
Code:
def data=(index) puts index.curr_sym return if @content == index @content = index refresh end
Does this make better sense?
Last edited by a moderator:
