RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[SOLVED] [ACE] Create multiple windows through a loop

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 55
Waiting ...
I seem to not be grasping this and maybe some one here can help me.

Lets assume that I have a Module with an array: VP::CONF::ARRAY_V which has 2 elements in it

Now lets assume in the scene_map I am creating a method called create_window_multi in this method I am doing something like:

Code: [Select]
## Check the array, are we NOT empty?
## Walk the array
## Create a window that is 20 pixels bellow the last window
def create_window_multi
    if !VP::CONF::ARRAY_V.empty?
        VP::CONF::ARRAY_V.each do |i|
            @window = Create_My_Window.new(10)
        end
    end
end

This does not work for me, the window is created but the window keeps moving down. Only one window is created when, as stated before VP::CONF::ARRAY_V  has 2 elements in it.

Thoughts?
« Last Edit: November 01, 2012, 05:23:24 PM by Vindictive Personality »

**
Rep:
Level 66
RMRK Junior
That example you posted makes no sense.. Why are you passing '10' as argument to that class anyway?  ???

**
Rep: +0/-0Level 55
Waiting ...
I thought I answered that LMAO. Apparently not.

heres the full thing, I decided to build it:

Code: [Select]

module VP
  module VAR
    VARIABLE = [10, 12, 15]
  end
end


class Gauge_Hud < Window_Base
  def initialize(y_axis)
    super(0, y_axis, window_width, window_height)
    refresh
  end
 
  def window_height
    return 60
  end
 
  def window_width
    return 180
  end
 
  def refresh
    contents.clear
    create_gauge
  end
 
  def create_gauge
    VP::VAR::VARIABLE.each do |x|
      draw_gauge(0, 0, 180, 0.5, text_color(3), text_color(20))
    end
   
  end
 
  def open
    refresh
    super
  end
end

class Scene_Map < Scene_Base
 
  alias create_all_windows_vp_rhn5 create_all_windows
  def create_all_windows
    create_all_windows_vp_rhn5
    create_gauge_window
  end
 
  def create_gauge_window
    if !VP::VAR::VARIABLE.empty?
      for x in VP::VAR::VARIABLE
        @gauge = Gauge_Hud.new(20)
      end
    end
  end
end


why is my window not being created multiple times? It should be. It needs to be.

**
Rep:
Level 66
RMRK Junior
Quote
why is my window not being created multiple times? It should be. It needs to be.
Well, first off, if you have the same 'y_axis' for all windows you create, then.. well, you're just gonna create windows that overlaps eachother which is the reason you can just see one of them. So replace your 'foreach' loop with;
Code: [Select]
VP::CONF::ARRAY_V.each_index { |i| @window = Create_My_Window.new((i+1)*10) }

See if that works.

**
Rep: +0/-0Level 55
Waiting ...
This is what happened (see attached file)

essentially all it does is move the window down instead of creating a new one
« Last Edit: October 31, 2012, 08:13:57 PM by Vindictive Personality »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
You can't just set them to the same variable like that. Once it loses its reference, the windows will eventually be freed. In this case, they won't ever even show up since you don't update Graphics before freeing them. 

So, you could do something like:

Code: [Select]

  def create_gauge_window
    if !VP::VAR::VARIABLE.empty?
      @gauge_windows = []
      for x in VP::VAR::VARIABLE
        @gauge_windows.push(Gauge_Hud.new(20))
      end
    end
  end

If you are using VX Ace, doing it that way will necesitate that you manually update and dispose the windows. If you wanted to take advantage of the methods already built for that, you would need to give each window its own instance variable. In that case, you could do something like this:

Code: [Select]

  def create_gauge_window
    if !VP::VAR::VARIABLE.empty?
      for i in 0...VP::VAR::VARIABLE.size
        set_instance_variable(:"@gauge_window_#{i+1}", Gauge_Hud.new(20))
      end
    end
  end

If you did that, the windows would be named @gauge_window_1, @gauge_window_2, @gauge_window_3. If you need to reference them, it would probably be wise to also put them inside an array so that you know how to get to them.

I also share Mango's concern about your y-axis being the same, but I also don't see what you're trying to do in that regard so I left that the same. There's no way you can fit 10, 12, or 15 of those windows in that resolution. You'd need between 600 and 900 vertical resolution. That said, you also need to fix that, as with either code I gave you, all the gauges would show up on top of each other.

Also, there's no reason to check if the array is empty if you are just iterating through the array anyway. Nothing will happen if it's empty.

Also, shouldn't there be some importance to the numbers in that array? You don't pass them to the gauge window at all.

**
Rep: +0/-0Level 55
Waiting ...
So I simplified:

Code: [Select]
module DataManager
  class << self
    alias create_gameobjects_vp_hdsfy45 create_game_objects
  end

  def self.create_game_objects
    create_gameobjects_vp_hdsfy45
    $game_gauge = Game_Guage.new
  end
   
end
 

class Game_Guage
  attr_accessor :variable_id
  attr_accessor :variable_max
  attr_accessor :show
 
  def set_var_id(id)
    @variable_id = id
  end
 
  def set_var_max(max)
    @variable_max = max
  end
 
  def set_show(show)
    @show = show
  end
end

class Scene_Map
 
  alias create_all_windows_vp_fhhjse5 create_all_windows
  def create_all_windows
    create_all_windows_vp_fhhjse5
    create_gauge
  end
 
  def create_gauge
    if $game_gauge.show = true
      @guage = Window_Gauge.new()
    end
  end
end

class Window_Gauge < Window_Base
 
  def initialize
    super(0, 0, window_width, fitting_height(1))
    refresh
  end

  def window_width
    return 180
  end

  def refresh
    contents.clear
    draw_gauge(0, 0, 160, fil_rate, text_color(10), text_color(5))
  end

  def fil_rate
    if $game_gauge.variable_id != nil
      puts $game_variable[$game_gauge.varaible_id]
      if $game_gauge.variable_max < $game_variables[$game_gauge.variable_id]
        @amount = 1.0/$game_variables[$game_gauge.variable_id]
      end
    else
      @amount = 0
    end
   
  end

  def open
    refresh
    super
  end
end

The problem is, I don't think I am understanding the refresh on windows, because once  $game_gauge.variable_id isn't nil shouldn't the window refresh?
« Last Edit: October 31, 2012, 10:32:01 PM by Vindictive Personality »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Sorry, it should have been instance_variable_set, but yeah, for the problem with the other code, you need to change the y. You are passing 20 as the y value for each window. If you don't want them to draw all on top of each other, then pass a different y value with something like what Mango was saying. maybe i*60 though.

Also, I hadn't looked at it before, but what's up with:

Code: [Select]
  def create_gauge
    VP::VAR::VARIABLE.each do |x|
      draw_gauge(0, 0, 180, 0.5, text_color(3), text_color(20))
    end

That is drawing all of the gauges on top of each other, but even if you fix the x and y positions, then I would assume that you either want each gauge to have its own window or else you want to draw them all in one window. You can do one or the other, but I don't see any reason you would want to do both. If you want to draw them all in one window, then you should make window_height dependent on the size of the VP::VAR::VARIABLE array and you need to modify the y value for each as you draw it, again similar to what Mango suggested, though you would need less room. If you want separate windows, then you should pass the variable ID to the window itself and just draw the gauge for that variable.

As for the VP::VAR::VARIABLE = 6 thing, you can do it, but you shouldn't really change the values of constants. If you want it to be something that varies, you should make it a variable and you should put it somewhere that it's saved with the save file.

**
Rep: +0/-0Level 55
Waiting ...
for the old code, I was trying to get the gauges all in one window, but abadonded that idea and didn't clean it up >.< as for the new code - My understanding of refresh is it refreshes all the time? but apparently not? just when instantiated?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
It can refresh whenever you call the method. You call it in the initialize method, so it happens in the initialize method. If you wanted it to happen every frame, you could define the update method and call it there. It would be preferable to refresh only when the value of the variable changes though.

**
Rep: +0/-0Level 55
Waiting ...
I figured that out and have come up with this:

Code: [Select]
module DataManager
  class << self
    alias create_gameobjects_vp_hdsfy45 create_game_objects
  end

  def self.create_game_objects
    create_gameobjects_vp_hdsfy45
    $game_gauge = Game_Gauge.new
  end
   
end
 
class Game_Gauge
  attr_accessor :variable_id
  attr_accessor :variable_max
  attr_accessor :show
 
  def set_var_id(id)
    @variable_id = id
  end
 
  def set_var_max(max)
    @variable_max = max
  end
 
  def set_show(show)
    @show = show
  end
end

class Scene_Map
 
  alias create_all_windows_vp_fhhjse5 create_all_windows
  def create_all_windows
    create_all_windows_vp_fhhjse5
    create_gauge
  end
 
  def create_gauge
    @gauge = Window_Gauge.new()
  end
 
end

class Window_Gauge < Window_Base
 
  def initialize
    super(0, 0, window_width, fitting_height(1))
    refresh
  end

  def window_width
    return 180
  end

  def refresh
    contents.clear
    draw_gauge(0, 0, 160, fil_rate, text_color(10), text_color(5))
  end
 
  def update
    super
    if $game_gauge.show
      self.visible = true
    else
      self.visible = false
    end
    fil_rate
  end

  def fil_rate
    if $game_gauge.variable_id != nil
      if $game_gauge.variable_max >= $game_variables[$game_gauge.variable_id]
        @amount = 1.0/$game_variables[$game_gauge.variable_id]
        puts "I am a new value of: #{@amount}"
      end
    else
      @amount = 0
    end
  end

  def open
    refresh
    super
  end
end

When the user interacts with an event the number in fil_rate (yes I know its spelt wrong, will fix) goes down, when it should start at 0.1 and go up to 1.

$game_gauge.variable_max = 10
$game_gauge.variable_id = 10 (with a max of, obviously, 10)